﻿using Intex.Tools;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Data;
using System.Linq;
using Intex.Tools;
using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using WPFExcelReport.Helpers;
using INTEX.DataBase;
namespace WPFExcelReport
{

    public partial class JLTONAV95Data : BaseFunction
    {
        string ABPLFD = "X";
        int ABPOS = 1;
        public decimal LDAB05 = 1;
        public decimal LDAB55 = 1;
        public decimal LDAB45 = 1;
        public decimal LDAB50 = 1;
        DataSet SetDispo = new DataSet();
        Queue<DataSet> JobQueue;
        DataSet Set4ITX = new DataSet();
        DataRow dwIntexStd = null;
        bool IsRun = false;
        string PRLO = "", PRLB = "", PRLP = "";
        string time;
        int ABAID = 1;
        public DataSet SetMap;
        public Convert2Intex Convert2Intex;
        public DataSet SetExt = new System.Data.DataSet();
        public DataSet SetJob;
        public SETINTEXDB SetData;
        DataTable tbABAUFM = null;
        Dictionary<string, string> pABPAUFLFD = new Dictionary<string, string>();
        JLTAB2INTEX m_wintex;
        BackgroundWorker bgWorker;
        public JLTONAV95Data()
            : base()
        {
            Helpers.Helper.GetDate(ref date, ref year, ref month, ref day);
        }
        public JLTONAV95Data(OracleConnection _OracleDB, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_OracleDB, _proxy, userID)
        {
            INTEXDBC = new INTEXDBC(_OracleDB, _proxy);
            Convert2Intex = new Convert2Intex();
            Helpers.Helper.GetDate(ref date, ref year, ref month, ref day);
            JobQueue = new Queue<DataSet>();
            bgWorker = new BackgroundWorker();
            bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
            bgWorker.RunWorkerCompleted += bgWorker_RunWorkerCompleted;
        }
        public JLTONAV95Data(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
            INTEXDBC = new INTEXDBC(OracleDB, proxy);
            Convert2Intex = new Convert2Intex();
            JobQueue = new Queue<DataSet>();
            Helpers.Helper.GetDate(ref date, ref year, ref month, ref day);
            bgWorker = new BackgroundWorker();
            bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
            bgWorker.RunWorkerCompleted += bgWorker_RunWorkerCompleted;
        }
        void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            IsRun = false;
        }
        void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (!IsRun)
            {
                IsRun = true;
            }
            AutoRun();
        }
        public DataSet LoadEnv()
        {
            DataSet SResult = new DataSet();
            DataSet SReturn = new DataSet();
            Helper.GetDate(ref date, ref year, ref month, ref day);
            SetMap = new DataSet();
            DataSet STemp = new System.Data.DataSet();
            string filePath = Path.Combine(PathHelper.ApplicationPath, "Report\\Interface\\JLTAV95MAPINTEX.XML");
            STemp.ReadXml(filePath);
            SetMap.Merge(STemp);
            filePath = Path.Combine(PathHelper.ApplicationPath, @"Report\Interface\PRODSETUP.XML");
            if (!System.IO.File.Exists(filePath))
            {
                return SReturn;
            }
            SResult.ReadXml(filePath);
            SReturn.Merge(SResult);
            DataRow dwData = INTEXDB.APFOLGE.NewRow();
            dwData["APFMANDANT"] = "00";
            SResult = INTEXDBC.QueryAPFOLGE(dwData, 3);
            SReturn.Merge(SResult);
            return SReturn;
        }

        public DataSet LoadData(DataRow dwInput)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            OracleCommand or1;
            string KRS = "";
            string LFD = "";
            try
            {
                KRS = dwInput["VKPAUFKRS"].ToString();
                LFD = dwInput["VKPAUFLFD"].ToString();
                DataRow dwData = INTEXDB.VKKOPF.NewRow();
                dwData["VKKMANDANT"] = "00";
                dwData["VKKAUFKRS"] = KRS;
                dwData["VKKAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryVKKOPF(dwData, 1);
                SReturn.Merge(SResult);
                dwData = INTEXDB.VKPOS.NewRow();
                dwData["VKPMANDANT"] = "00";
                dwData["VKPAUFKRS"] = KRS;
                dwData["VKPAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryVKPOS(dwData, 2);
                SReturn.Merge(SResult);
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryAPZUORD(dwData, 2);
                SReturn.Merge(SResult);
                SResult = INTEXDBC.QueryAPZUORD(dwData, 3);
                SReturn.Merge(SResult);
                SResult = INTEXDBC.QueryAPZUORD(dwData, 4);
                SReturn.Merge(SResult);
                SResult = INTEXDBC.QueryAPZUORD(dwData, 5);
                SReturn.Merge(SResult);
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                DataSet STemp = new System.Data.DataSet();
                if (SReturn.Tables.Contains("APZUORD"))
                {
                    string processed = "";
                    foreach (DataRow rx in SReturn.Tables["APZUORD"].Rows)
                    {
                        string APZANRKRS = rx["APZANRKRS"].ToString();
                        string APZALFDNR = rx["APZALFDNR"].ToString();
                        if (processed.Contains(APZANRKRS + APZALFDNR + ";"))
                            continue;
                        processed += APZANRKRS + APZALFDNR + ";";
                        dwData = INTEXDB.APFOLGE.NewRow();
                        dwData["APFMANDANT"] = rx["APZMANDANT"];
                        dwData["APFANRKRS"] = APZANRKRS;
                        dwData["APFALFDNR"] = APZALFDNR;
                        SResult = INTEXDBC.QueryAPFOLGE(dwData, 4);
                        STemp.Merge(SResult);
                        dwData = INTEXDB.APARTK.NewRow();
                        dwData["APAKMANDANT"] = rx["APZMANDANT"];
                        dwData["APAKANRKRS"] = APZANRKRS;
                        dwData["APAKALFDNR"] = APZALFDNR;
                        SResult = INTEXDBC.QueryAPARTK(dwData, 1);
                        STemp.Merge(SResult);
                    }
                    SReturn.Merge(STemp);
                }
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryWDECK(dwData, 4);
                SReturn.Merge(SResult);
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryWASTAMM(dwData, 5);
                SReturn.Merge(SResult);
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryWASTKE(dwData, 2);
                SReturn.Merge(SResult);
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                dwData["WDSA"] = "C";
                SResult = INTEXDBC.QueryWAFARBEN(dwData, 6);
                SReturn.Merge(SResult);
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                dwData["WDSA"] = "B";
                SResult = INTEXDBC.QueryWAFARBEN(dwData, 7);
                SReturn.Merge(SResult);

                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryWASTGA(dwData, 4);
                SReturn.Merge(SResult);
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryBSSATZ(dwData, 2);
                SReturn.Merge(SResult);
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryBSGROE(dwData, 2);
                SReturn.Merge(SResult);
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryBHSATZ(dwData, 2);
                SReturn.Merge(SResult);
                dwData = INTEXDB.WDECK.NewRow();
                dwData["WDMANDANT"] = "00";
                dwData["WDAUFKRS"] = KRS;
                dwData["WDAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryBASTGA(dwData, 2);
                SReturn.Merge(SResult);
                STemp = new System.Data.DataSet();
                string yarns = "";
                string Yart = "";
                string Yvar = "";
                foreach (DataRow row in SReturn.Tables["WASTGA"].Rows)
                {
                    dwData = INTEXDB.GSDAT.NewRow();
                    Yart = row["WAGGART"].ToString();
                    Yvar = row["WAGGVAR"].ToString();
                    if (yarns.Contains(Yart + Yvar + ";"))
                    {
                        continue;
                    }
                    yarns += Yart + Yvar + ";";
                    dwData["GSMANDANT"] = row["WAGMANDANT"];
                    dwData["GSART"] = Yart;
                    dwData["GSVAR"] = Yvar;
                    SResult = INTEXDBC.QueryGSDAT(dwData);
                    STemp.Merge(SResult);
                }
                SReturn.Merge(STemp);
                STemp = new System.Data.DataSet();
                foreach (DataRow row in SReturn.Tables["BASTGA"].Rows)
                {
                    Yart = row["BAGGART"].ToString();
                    Yvar = row["BAGGVAR"].ToString();
                    if (yarns.Contains(Yart + Yvar + ";"))
                    {
                        continue;
                    }
                    yarns += Yart + Yvar + ";";
                    dwData = INTEXDB.GSDAT.NewRow();
                    dwData["GSMANDANT"] = row["BAGMANDANT"];
                    dwData["GSART"] = Yart;
                    dwData["GSVAR"] = Yvar;
                    SResult = INTEXDBC.QueryGSDAT(dwData);
                    STemp.Merge(SResult);
                    dwData = INTEXDB.GASTGA.NewRow();
                    dwData["GAGMANDANT"] = row["BAGMANDANT"];
                    dwData["GAGART"] = Yart;
                    SResult = INTEXDBC.QueryGASTGA(dwData, 2);
                    STemp.Merge(SResult);
                }
                SReturn.Merge(STemp);
                foreach (DataRow row in SReturn.Tables["GSDAT"].Rows)
                {
                    dwData = INTEXDB.GASTGA.NewRow();
                    dwData["GAGMANDANT"] = row["GSMANDANT"];
                    dwData["GAGART"] = row["GSART"];
                    SResult = INTEXDBC.QueryGASTGA(dwData, 2);
                    STemp.Merge(SResult);
                }
                SReturn.Merge(STemp);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }

        #region======Run===========

        public DataSet InsertABFOLGE(DataRow dwABPOS, string SampleKRS = "T6", string SampleLFD = "005116", string SamplePOS = "010")
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            OracleCommand or1;
            DataRow dwLocal;
            try
            {

                #region============MAPDATA=========================
                string APFMANDANT, ABPANRKR = "", ABPALFDNR = "";
                dwLocal = SetData.ABFOLGE.NewABFOLGERow();
                dwLocal["ABFMANDANT"] = dwABPOS["ABPMANDANT"];
                dwLocal["ABFAUFKRS"] = dwABPOS["ABPAUFKRS"];
                dwLocal["ABFAUFLFD"] = dwABPOS["ABPAUFLFD"];
                dwLocal["ABFAUFPOS"] = dwABPOS["ABPAUFPOS"];
                dwLocal["ABFNEUBEN"] = dwABPOS["ABPNEUBEN"];
                dwLocal["ABFNEUDAT"] = dwABPOS["ABPNEUDAT"];

                APFMANDANT = dwABPOS["ABPMANDANT"].ToString();
                ABPANRKR = dwABPOS["ABPANRKR"].ToString();
                ABPALFDNR = dwABPOS["ABPALFDNR"].ToString();
                #endregion

                #region============APFOLGE=========================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM ABFOLGE WHERE ABFMANDANT=:ABFMANDANT AND ABFAUFKRS=:ABFAUFKRS AND ABFAUFLFD=:ABFAUFLFD AND ABFAUFPOS=:ABFAUFPOS";
                or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = "00";
                or1.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = SampleKRS;
                or1.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = SampleLFD;
                or1.Parameters.Add("ABFAUFPOS", OracleType.NVarChar).Value = SamplePOS;

                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "ABFOLGE";
                }
                #endregion
                string APFSOLLME = "1";
                foreach (DataRow dwABFOLGE in setResult.Tables["ABFOLGE"].Rows)
                {
                    dwLocal.ItemArray = dwABFOLGE.ItemArray;
                    dwLocal["ABFSOLLSTK"] = System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE8"]) * 0.01, 0);

                    dwLocal["ABFSOLLSTART"] = dwABPOS["ABPSTARTDAT"];
                    dwLocal["ABFSOLLDAT"] = dwABPOS["ABPENDDAT"];
                    dwLocal["ABFSOLLSTARTA"] = dwABPOS["ABPSTARTDAT"];
                    dwLocal["ABFSOLLDATA"] = dwABPOS["ABPENDDAT"];
                    dwLocal["ABFMANDANT"] = dwABPOS["ABPMANDANT"];
                    dwLocal["ABFAUFKRS"] = dwABPOS["ABPAUFKRS"];
                    dwLocal["ABFAUFLFD"] = dwABPOS["ABPAUFLFD"];
                    dwLocal["ABFAUFPOS"] = dwABPOS["ABPAUFPOS"];
                    dwLocal["ABFNEUBEN"] = dwABPOS["ABPNEUBEN"];
                    dwLocal["ABFNEUDAT"] = dwABPOS["ABPNEUDAT"];
                    dwLocal["ABFTSDAT"] = iDate;
                    APFSOLLME = dwABFOLGE["ABFSOLLME"].ToString();
                    long ABFSOLLMG = 0, ABFSOLLMTR = 0;
                    switch (APFSOLLME)
                    {
                        case "1":
                            ABFSOLLMG = System.Convert.ToInt64(System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE1"]) * 10.0, 0));
                            ABFSOLLMTR = System.Convert.ToInt64(System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE1"]) * 10.0, 0));
                            break;
                        case "2":
                            ABFSOLLMG = System.Convert.ToInt64(System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE2"]) * 10.0, 0));
                            ABFSOLLMTR = System.Convert.ToInt64(System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE1"]) * 10.0, 0));
                            break;
                        case "3":
                            ABFSOLLMG = System.Convert.ToInt64(System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE3"]) * 0.1, 0));
                            break;
                        case "4":
                            ABFSOLLMG = System.Convert.ToInt64(System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE4"]) * 0.1, 0));
                            break;
                        case "5":
                            ABFSOLLMG = System.Convert.ToInt64(System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE5"]) * 10.0, 0));
                            break;
                        case "6":
                            ABFSOLLMG = System.Convert.ToInt64(System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE6"]) * 0.1, 0));
                            break;
                        case "7":
                            ABFSOLLMG = System.Convert.ToInt64(System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE7"]) * 0.1, 0));
                            break;
                        case "8":
                            ABFSOLLMG = System.Convert.ToInt64(System.Math.Round(System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE8"]) * 0.1, 0));
                            break;
                        default:
                            break;

                    }
                    dwLocal["ABFSOLLMG"] = ABFSOLLMG;
                    dwLocal["ABFSOLLMTR"] = ABFSOLLMTR;



                    #region============INSERT==========================
                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = "INSERT INTO ABFOLGE(ABFMANDANT, ABFAUFKRS, ABFAUFLFD, ABFAUFPOS, ABFAFOLGE, ABFAENDZL, ABFAENDBEN, ABFAENDDAT, ABFNEUBEN, ABFNEUDAT, ABFPLANKZ, ABFKSTKRS, ABFKST, ABFSPLPOS, ABFAGANG, ABFBZAGANG, ABFMTYP, ABFLIEFNR, ABFMNRKRS, ABFMLFDNR, ABFMPOS, ABFMPLPOS, ABFMANUELKZ, ABFPARALKZ, ABFSOLLSTK, ABFSOLLMG, ABFSOLLME, ABFSOLLMTR, ABFLAEAEND, ABFGEWAEND, ABFBASMGE, ABFME, ABFFIX, ABFAGRVON, ABFAGRBIS, ABFMASCHANZ, ABFMASCHZE, ABFMASCHZT, ABFLIAFOLGE1, ABFLIART1, ABFLIMIUZ1, ABFLIMAUZ1, ABFLIMIWM1, ABFLIABS1, ABFLIABSZE1, ABFLIAFOLGE2, ABFLIART2, ABFLIMIUZ2, ABFLIMAUZ2, ABFLIMIWM2, ABFLIABS2, ABFLIABSZE2, ABFLIAFOLGE3, ABFLIART3, ABFLIMIUZ3, ABFLIMAUZ3, ABFLIMIWM3, ABFLIABS3, ABFLIABSZE3, ABFLIAFOLGE4, ABFLIART4, ABFLIMIUZ4, ABFLIMAUZ4, ABFLIMIWM4, ABFLIABS4, ABFLIABSZE4, ABFLIAFOLGE5, ABFLIART5, ABFLIMIUZ5, ABFLIMAUZ5, ABFLIMIWM5, ABFLIABS5, ABFLIABSZE5, ABFPERSANZ, ABFPERSZE, ABFPERSZT, ABFPERSMB, ABFRUESTZE, ABFRUESTZT, ABFRPERSZT, ABFANZMA, ABFFAKTOR, ABFFAKTORBLG, ABFABEARBZT, ABFARUESTZT, ABFAMASCHZT, ABFAPERSZT, ABFANZAF, ABFVERWZE, ABFVERWZTV, ABFVERWZTB, ABFVLFZT, ABFVLFZTZE, ABFSOLLSTART, ABFSOLLDAT, ABFSOLLSTARTA, ABFSOLLDATA, ABFFIXTERM, ABFRUECKKZ, ABFKENNUNG, ABFSONDERKZ, ABFZUSATZ1, ABFZUSATZ2, ABFZUSATZ3, ABFZUSATZ4, ABFZUSATZ5, ABFFZUSATZKZ1, ABFFZUSATZKZ2, ABFFZUSATZKZ3, ABFFZUSATZKZ4, ABFFZUSATZKZ5, ABFZUSTAND, ABFFERTIG, ABFMATABR, ABFDOMPART, ABFLAGPLKZ, ABFLO, ABFLB, ABFLP, ABFAUFBKZ, ABFPRUEFANW, ABFPROBE, ABFSPSTA, ABFSPGRD, ABFMEKOPFKZ, ABFSTATUS, ABFRUECKMKZ, ABFRAFOLGE, ABFRUECKDAT, ABFRUECKZT, ABFIMNRKRS, ABFIMLFDNR, ABFIMPOS, ABFISTK, ABFIMG, ABFIMTR, ABFIDIFFMG, ABFISTARTDAT, ABFISTARTZT, ABFIENDDAT, ABFIENDZT, ABFANZTLG, ABFRETOURKZ, ABFREAUFKRS, ABFREAUFLFD, ABFREAUFPOS, ABFSTUFE, ABFWERK, ABFANRKRS, ABFALFDNR, ABFSAFOLGE, ABFAEVOR, ABFEINSTKA, ABFBANRKRS, ABFBALFDNR, ABFEVARHNR, ABFEVARUNR, ABFRUESTFAM, ABFBNRKRS, ABFBLFDNR, ABFBPOS, ABFVONMOD, ABFBISMOD, ABFBLOCKKZ1, ABFBLOCKKZ2, ABFPAPIERKZ, ABFKALKKZ, ABFALTKSTKZ, ABFBDEKEN, ABFPRIO, ABFSTATKZ, ABFPROZMG, ABFMLMG, ABFQUALI, ABFLGRP, ABFLART, ABFLZDR, ABFPRBMGZT, ABFZEITLN, ABFPENETTO, ABFPLKOST, ABFLABDIPS, ABFNBREP, ABFAGENTF, ABFBAFOLGE, ABFVNAME, ABFFLAG, ABFEGVNAME1, ABFEGFLAG1, ABFEGVNAME2, ABFEGFLAG2, ABFEGVNAME3, ABFEGFLAG3, ABFEGVNAME4, ABFEGFLAG4, ABFEGVNAME5, ABFEGFLAG5, ABFMKFS, ABFMKFI, ABFMKGS, ABFMKGI, ABFMKKS, ABFMKKI, ABFMKRWS, ABFMKRWI, ABFMKFWS, ABFMKFWI, ABFMKSOS, ABFMKSOI, ABFMKTS, ABFMKTI, ABFMKUS, ABFMKUI, ABFMKREZFS, ABFMKREZFI, ABFMKREZCS, ABFMKREZCI, ABFMGKS1, ABFMGKS2, ABFMGKS3, ABFMGKS4, ABFMGKS5, ABFMGKI1, ABFMGKI2, ABFMGKI3, ABFMGKI4, ABFMGKI5, ABFFKMS1, ABFFKMS2, ABFFKMS3, ABFFKMS4, ABFFKMS5, ABFFKMI1, ABFFKMI2, ABFFKMI3, ABFFKMI4, ABFFKMI5, ABFFKPS1, ABFFKPS2, ABFFKPS3, ABFFKPS4, ABFFKPS5, ABFFKPI1, ABFFKPI2, ABFFKPI3, ABFFKPI4, ABFFKPI5, ABFFGKS1, ABFFGKS2, ABFFGKS3, ABFFGKS4, ABFFGKS5, ABFFGKI1, ABFFGKI2, ABFFGKI3, ABFFGKI4, ABFFGKI5, ABFFFKS, ABFFFKI, ABFIMZT, ABFIPZT, ABFIRML, ABFIRMS, ABFIRPZ, ABFBNRZ, ABFSCHBSTA, ABFWARSTA, ABFBSMENGE, ABFFBSTA, ABFGEBNR, ABFBEHNRT, ABFBEHNRN, ABFFBBELO, ABFFBBELB, ABFFBBELP, ABFSTOPSTA, ABFSTOPGRD, ABFZUSKZ, ABFERSTKZ, ABFLAEAENDO, ABFPRUEFGEN, ABFCWEIGHT, ABFRUECKBEN, ABFKETTANZ, ABFMETHODE, ABFRZKZ, ABFREWEIL, ABFURLAND, ABFTSDAT, ABFTSAFO, ABFTEDAT, ABFTEAFO, ABFTSSDAT, ABFTESDAT, ABFFILLER)"
    + "VALUES (:ABFMANDANT, :ABFAUFKRS, :ABFAUFLFD, :ABFAUFPOS, :ABFAFOLGE, 1, '        ', 0, :ABFNEUBEN, :ABFNEUDAT, 'J', '  ', '    ', '   ', '               ', '                                                            ', '        ', '        ', '  ', '0000', '00', 9999, 'J', 'N', 14, 2671640, '1', 2671640, 0, 0, 100000, '1', 'N', 0, 0, 0, '  ', 0, '000', '  ', 0, 0, 0, 0, '  ', '000', '  ', 0, 0, 0, 0, '  ', '000', '  ', 0, 0, 0, 0, '  ', '000', '  ', 0, 0, 0, 0, '  ', '000', '  ', 0, 0, 0, 0, '  ', 0, 'MI', 100, 0, '  ', 0, 0, 10000, 0, 0, 27, 0, 0, 27, 0, '  ', 0, 0, 300, 'TG', 20110822, 20110825, 20110822, 20110825, ' ', 'P', '  ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '    ', 'N', ' ', 'N', 'N', '  ', '  ', '        ', ' ', 'N', 'N', ' ', '                              ', ' ', ' ', ' ', '000', 0, 0, '  ', '0000', '00', 0, 0, 0, 0, 0, 0, 0, 0, 0, 'N', '  ', '000000', '000', 'F', '   ', 'TX', '004950', '010', '0000', 'N', '  ', '000000', '  ', '  ', '          ', '  ', '0000', '00', 0, 0, ' ', '0', 'J', 'J', ' ', '  ', '00', ' ', 0, 0, '      ', '      ', '      ', ' ', 0, ' ', 0, ' ', 0, 0, ' ', '000', '     ', 0, '     ', 0, '     ', 0, '     ', 0, '     ', 0, '     ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', 0, ' ', '        ', '000000', '  ', '  ', '  ', '        ', '  ', '   ', '  ', ' ', '00', ' ', 0, '        ', 0, '        ', ' ', '  ', '   ', 20110822, '000', 0, '000', 20110822, 20110825, '                                                                                                                 ')";

                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwLocal["ABFMANDANT"];
                    or1.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = dwLocal["ABFAUFKRS"];
                    or1.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = dwLocal["ABFAUFLFD"];
                    or1.Parameters.Add("ABFAUFPOS", OracleType.NVarChar).Value = dwLocal["ABFAUFPOS"];
                    or1.Parameters.Add("ABFAFOLGE", OracleType.NVarChar).Value = dwLocal["ABFAFOLGE"];
                    or1.Parameters.Add("ABFNEUBEN", OracleType.NVarChar).Value = dwLocal["ABFNEUBEN"];
                    or1.Parameters.Add("ABFNEUDAT", OracleType.NVarChar).Value = dwLocal["ABFNEUDAT"];
                    setResult = Connect2Proxy(or1);
                    #endregion

                    #region============UPDATE==========================

                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = "UPDATE ABFOLGE SET "
                    + "ABFTEAFO=:ABFTEAFO,ABFTSSDAT=:ABFTSSDAT,ABFTESDAT=:ABFTESDAT,ABFFILLER=:ABFFILLER,ABFMLMG=:ABFMLMG,ABFQUALI=:ABFQUALI,ABFLGRP=:ABFLGRP,ABFLART=:ABFLART"
                    + ",ABFLZDR=:ABFLZDR,ABFPRBMGZT=:ABFPRBMGZT,ABFZEITLN=:ABFZEITLN,ABFPENETTO=:ABFPENETTO,ABFPLKOST=:ABFPLKOST,ABFLABDIPS=:ABFLABDIPS,ABFNBREP=:ABFNBREP,ABFAGENTF=:ABFAGENTF"
                    + ",ABFBAFOLGE=:ABFBAFOLGE,ABFVNAME=:ABFVNAME,ABFFLAG=:ABFFLAG,ABFEGVNAME1=:ABFEGVNAME1,ABFEGFLAG1=:ABFEGFLAG1,ABFEGVNAME2=:ABFEGVNAME2,ABFEGFLAG2=:ABFEGFLAG2,ABFEGVNAME3=:ABFEGVNAME3"
                    + ",ABFEGFLAG3=:ABFEGFLAG3,ABFEGVNAME4=:ABFEGVNAME4,ABFEGFLAG4=:ABFEGFLAG4,ABFEGVNAME5=:ABFEGVNAME5,ABFEGFLAG5=:ABFEGFLAG5,ABFMKFS=:ABFMKFS,ABFMKFI=:ABFMKFI,ABFMKGS=:ABFMKGS"
                    + ",ABFMKGI=:ABFMKGI,ABFMKKS=:ABFMKKS,ABFMKKI=:ABFMKKI,ABFMKRWS=:ABFMKRWS,ABFMKRWI=:ABFMKRWI,ABFMKFWS=:ABFMKFWS,ABFMKFWI=:ABFMKFWI,ABFMKSOS=:ABFMKSOS"
                    + ",ABFMKSOI=:ABFMKSOI,ABFMKTS=:ABFMKTS,ABFMKTI=:ABFMKTI,ABFMKUS=:ABFMKUS,ABFMKUI=:ABFMKUI,ABFMKREZFS=:ABFMKREZFS,ABFMKREZFI=:ABFMKREZFI,ABFMKREZCS=:ABFMKREZCS"
                    + ",ABFMKREZCI=:ABFMKREZCI,ABFMGKS1=:ABFMGKS1,ABFMGKS2=:ABFMGKS2,ABFMGKS3=:ABFMGKS3,ABFMGKS4=:ABFMGKS4,ABFMGKS5=:ABFMGKS5,ABFMGKI1=:ABFMGKI1,ABFMGKI2=:ABFMGKI2,ABFMGKI3=:ABFMGKI3,"
                    + "ABFMGKI4=:ABFMGKI4,ABFMGKI5=:ABFMGKI5,ABFFKMS1=:ABFFKMS1,ABFFKMS2=:ABFFKMS2,ABFFKMS3=:ABFFKMS3,ABFFKMS4=:ABFFKMS4,ABFFKMS5=:ABFFKMS5,ABFFKMI1=:ABFFKMI1,ABFFKMI2=:ABFFKMI2,ABFFKMI3=:ABFFKMI3,ABFFKMI4=:ABFFKMI4"
                    + ",ABFFKMI5=:ABFFKMI5,ABFFKPS1=:ABFFKPS1,ABFFKPS2=:ABFFKPS2,ABFFKPS3=:ABFFKPS3,ABFFKPS4=:ABFFKPS4,ABFFKPS5=:ABFFKPS5,ABFFKPI1=:ABFFKPI1,ABFFKPI2=:ABFFKPI2,ABFFKPI3=:ABFFKPI3,ABFFKPI4=:ABFFKPI4"
                    + ",ABFFKPI5=:ABFFKPI5,ABFFGKS1=:ABFFGKS1,ABFFGKS2=:ABFFGKS2,ABFFGKS3=:ABFFGKS3,ABFFGKS4=:ABFFGKS4,ABFFGKS5=:ABFFGKS5,ABFFGKI1=:ABFFGKI1,ABFFGKI2=:ABFFGKI2,ABFFGKI3=:ABFFGKI3,ABFFGKI4=:ABFFGKI4"
                    + ",ABFFGKI5=:ABFFGKI5,ABFFFKS=:ABFFFKS,ABFFFKI=:ABFFFKI,ABFIMZT=:ABFIMZT,ABFIPZT=:ABFIPZT,ABFIRML=:ABFIRML,ABFIRMS=:ABFIRMS,ABFIRPZ=:ABFIRPZ,ABFBNRZ=:ABFBNRZ,ABFSCHBSTA=:ABFSCHBSTA,ABFWARSTA=:ABFWARSTA,ABFBSMENGE=:ABFBSMENGE"
                    + ",ABFFBSTA=:ABFFBSTA,ABFGEBNR=:ABFGEBNR,ABFBEHNRT=:ABFBEHNRT,ABFBEHNRN=:ABFBEHNRN,ABFFBBELO=:ABFFBBELO,ABFFBBELB=:ABFFBBELB,ABFFBBELP=:ABFFBBELP,ABFSTOPSTA=:ABFSTOPSTA,ABFSTOPGRD=:ABFSTOPGRD,ABFZUSKZ=:ABFZUSKZ,ABFERSTKZ=:ABFERSTKZ,ABFLAEAENDO=:ABFLAEAENDO"
                    + ",ABFPRUEFGEN=:ABFPRUEFGEN,ABFCWEIGHT=:ABFCWEIGHT,ABFRUECKBEN=:ABFRUECKBEN,ABFKETTANZ=:ABFKETTANZ,ABFMETHODE=:ABFMETHODE,ABFRZKZ=:ABFRZKZ,ABFREWEIL=:ABFREWEIL"
                    + ",ABFURLAND=:ABFURLAND,ABFTSDAT=:ABFTSDAT,ABFTSAFO=:ABFTSAFO,ABFTEDAT=:ABFTEDAT,ABFLIMAUZ3=:ABFLIMAUZ3,ABFLIMIWM3=:ABFLIMIWM3,ABFLIABS3=:ABFLIABS3,ABFLIABSZE3=:ABFLIABSZE3"
                    + ",ABFLIAFOLGE4=:ABFLIAFOLGE4,ABFLIART4=:ABFLIART4,ABFLIMIUZ4=:ABFLIMIUZ4,ABFLIMAUZ4=:ABFLIMAUZ4,ABFLIMIWM4=:ABFLIMIWM4,ABFLIABS4=:ABFLIABS4,ABFLIABSZE4=:ABFLIABSZE4"
                    + ",ABFLIAFOLGE5=:ABFLIAFOLGE5,ABFLIART5=:ABFLIART5,ABFLIMIUZ5=:ABFLIMIUZ5,ABFLIMAUZ5=:ABFLIMAUZ5,ABFLIMIWM5=:ABFLIMIWM5,ABFLIABS5=:ABFLIABS5,ABFLIABSZE5=:ABFLIABSZE5"
                    + ",ABFPERSANZ=:ABFPERSANZ,ABFPERSZE=:ABFPERSZE,ABFPERSZT=:ABFPERSZT,ABFPERSMB=:ABFPERSMB,ABFRUESTZE=:ABFRUESTZE,ABFRUESTZT=:ABFRUESTZT,ABFRPERSZT=:ABFRPERSZT"
                    + ",ABFANZMA=:ABFANZMA,ABFFAKTOR=:ABFFAKTOR,ABFFAKTORBLG=:ABFFAKTORBLG,ABFABEARBZT=:ABFABEARBZT,ABFARUESTZT=:ABFARUESTZT,ABFAMASCHZT=:ABFAMASCHZT,ABFAPERSZT=:ABFAPERSZT"
                    + ",ABFANZAF=:ABFANZAF,ABFVERWZE=:ABFVERWZE,ABFVERWZTV=:ABFVERWZTV,ABFVERWZTB=:ABFVERWZTB,ABFVLFZT=:ABFVLFZT,ABFVLFZTZE=:ABFVLFZTZE,ABFSOLLSTART=:ABFSOLLSTART,ABFSOLLDAT=:ABFSOLLDAT"
                    + ",ABFSOLLSTARTA=:ABFSOLLSTARTA,ABFSOLLDATA=:ABFSOLLDATA,ABFFIXTERM=:ABFFIXTERM,ABFRUECKKZ=:ABFRUECKKZ,ABFKENNUNG=:ABFKENNUNG,ABFSONDERKZ=:ABFSONDERKZ,ABFZUSATZ1=:ABFZUSATZ1"
                    + ",ABFZUSATZ2=:ABFZUSATZ2,ABFZUSATZ3=:ABFZUSATZ3,ABFZUSATZ4=:ABFZUSATZ4,ABFZUSATZ5=:ABFZUSATZ5,ABFFZUSATZKZ1=:ABFFZUSATZKZ1,ABFFZUSATZKZ2=:ABFFZUSATZKZ2"
                    + ",ABFFZUSATZKZ3=:ABFFZUSATZKZ3,ABFFZUSATZKZ4=:ABFFZUSATZKZ4,ABFFZUSATZKZ5=:ABFFZUSATZKZ5,ABFZUSTAND=:ABFZUSTAND,ABFFERTIG=:ABFFERTIG,ABFMATABR=:ABFMATABR"
                    + ",ABFDOMPART=:ABFDOMPART,ABFLAGPLKZ=:ABFLAGPLKZ,ABFLO=:ABFLO,ABFLB=:ABFLB,ABFLP=:ABFLP,ABFAUFBKZ=:ABFAUFBKZ,ABFPRUEFANW=:ABFPRUEFANW,ABFPROBE=:ABFPROBE,ABFSPSTA=:ABFSPSTA"
                    + ",ABFSPGRD=:ABFSPGRD,ABFMEKOPFKZ=:ABFMEKOPFKZ,ABFSTATUS=:ABFSTATUS,ABFRUECKMKZ=:ABFRUECKMKZ,ABFRAFOLGE=:ABFRAFOLGE,ABFRUECKDAT=:ABFRUECKDAT,ABFRUECKZT=:ABFRUECKZT,ABFIMNRKRS=:ABFIMNRKRS"
                    + ",ABFIMLFDNR=:ABFIMLFDNR,ABFIMPOS=:ABFIMPOS,ABFISTK=:ABFISTK,ABFIMG=:ABFIMG,ABFIMTR=:ABFIMTR,ABFIDIFFMG=:ABFIDIFFMG,ABFISTARTDAT=:ABFISTARTDAT,ABFISTARTZT=:ABFISTARTZT"
                    + ",ABFIENDDAT=:ABFIENDDAT,ABFIENDZT=:ABFIENDZT,ABFANZTLG=:ABFANZTLG,ABFRETOURKZ=:ABFRETOURKZ,ABFREAUFKRS=:ABFREAUFKRS,ABFREAUFLFD=:ABFREAUFLFD,ABFREAUFPOS=:ABFREAUFPOS"
                    + ",ABFSTUFE=:ABFSTUFE,ABFWERK=:ABFWERK,ABFANRKRS=:ABFANRKRS,ABFALFDNR=:ABFALFDNR,ABFSAFOLGE=:ABFSAFOLGE,ABFAEVOR=:ABFAEVOR,ABFEINSTKA=:ABFEINSTKA,ABFBANRKRS=:ABFBANRKRS"
                    + ",ABFBALFDNR=:ABFBALFDNR,ABFEVARHNR=:ABFEVARHNR,ABFEVARUNR=:ABFEVARUNR,ABFRUESTFAM=:ABFRUESTFAM,ABFBNRKRS=:ABFBNRKRS,ABFBLFDNR=:ABFBLFDNR,ABFBPOS=:ABFBPOS"
                    + ",ABFVONMOD=:ABFVONMOD,ABFBISMOD=:ABFBISMOD,ABFBLOCKKZ1=:ABFBLOCKKZ1,ABFBLOCKKZ2=:ABFBLOCKKZ2,ABFPAPIERKZ=:ABFPAPIERKZ,ABFKALKKZ=:ABFKALKKZ"
                    + ",ABFALTKSTKZ=:ABFALTKSTKZ,ABFBDEKEN=:ABFBDEKEN,ABFPRIO=:ABFPRIO,ABFSTATKZ=:ABFSTATKZ,ABFPROZMG=:ABFPROZMG,ABFMANDANT=:ABFMANDANT,ABFAUFKRS=:ABFAUFKRS"
                    + ",ABFAUFLFD=:ABFAUFLFD,ABFAUFPOS=:ABFAUFPOS,ABFAFOLGE=:ABFAFOLGE,ABFAENDZL=:ABFAENDZL,ABFAENDBEN=:ABFAENDBEN,ABFAENDDAT=:ABFAENDDAT,ABFNEUBEN=:ABFNEUBEN,ABFNEUDAT=:ABFNEUDAT"
                    + ",ABFPLANKZ=:ABFPLANKZ,ABFKSTKRS=:ABFKSTKRS,ABFKST=:ABFKST,ABFSPLPOS=:ABFSPLPOS,ABFAGANG=:ABFAGANG,ABFBZAGANG=:ABFBZAGANG,ABFMTYP=:ABFMTYP,ABFLIEFNR=:ABFLIEFNR"
                    + ",ABFMNRKRS=:ABFMNRKRS,ABFMLFDNR=:ABFMLFDNR,ABFMPOS=:ABFMPOS,ABFMPLPOS=:ABFMPLPOS,ABFMANUELKZ=:ABFMANUELKZ,ABFPARALKZ=:ABFPARALKZ,ABFSOLLSTK=:ABFSOLLSTK,ABFSOLLMG=:ABFSOLLMG,ABFSOLLME=:ABFSOLLME,ABFSOLLMTR=:ABFSOLLMTR,ABFLAEAEND=:ABFLAEAEND"
                    + ",ABFGEWAEND=:ABFGEWAEND,ABFBASMGE=:ABFBASMGE,ABFME=:ABFME,ABFFIX=:ABFFIX,ABFAGRVON=:ABFAGRVON,ABFAGRBIS=:ABFAGRBIS,ABFMASCHANZ=:ABFMASCHANZ,ABFMASCHZE=:ABFMASCHZE,ABFMASCHZT=:ABFMASCHZT"
                    + ",ABFLIAFOLGE1=:ABFLIAFOLGE1,ABFLIART1=:ABFLIART1,ABFLIMIUZ1=:ABFLIMIUZ1,ABFLIMAUZ1=:ABFLIMAUZ1,ABFLIMIWM1=:ABFLIMIWM1,ABFLIABS1=:ABFLIABS1,ABFLIABSZE1=:ABFLIABSZE1,ABFLIAFOLGE2=:ABFLIAFOLGE2,ABFLIART2=:ABFLIART2,ABFLIMIUZ2=:ABFLIMIUZ2,ABFLIMAUZ2=:ABFLIMAUZ2"
                    + ",ABFLIMIWM2=:ABFLIMIWM2,ABFLIABS2=:ABFLIABS2,ABFLIABSZE2=:ABFLIABSZE2,ABFLIAFOLGE3=:ABFLIAFOLGE3,ABFLIART3=:ABFLIART3,ABFLIMIUZ3=:ABFLIMIUZ3"
                    + " WHERE ABFMANDANT=:ABFMANDANT AND ABFAUFKRS=:ABFAUFKRS AND ABFAUFLFD=:ABFAUFLFD  AND ABFAUFPOS=:ABFAUFPOS AND ABFAFOLGE=:ABFAFOLGE";
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwLocal["ABFMANDANT"];
                    or1.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = dwLocal["ABFAUFKRS"];
                    or1.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = dwLocal["ABFAUFLFD"];
                    or1.Parameters.Add("ABFAUFPOS", OracleType.NVarChar).Value = dwLocal["ABFAUFPOS"];
                    or1.Parameters.Add("ABFAFOLGE", OracleType.NVarChar).Value = dwLocal["ABFAFOLGE"];

                    or1.Parameters.Add("ABFTEAFO", OracleType.NVarChar).Value = dwLocal["ABFTEAFO"];
                    or1.Parameters.Add("ABFTSSDAT", OracleType.NVarChar).Value = dwLocal["ABFTSSDAT"];
                    or1.Parameters.Add("ABFTESDAT", OracleType.NVarChar).Value = dwLocal["ABFTESDAT"];
                    or1.Parameters.Add("ABFFILLER", OracleType.NVarChar).Value = dwLocal["ABFFILLER"];
                    or1.Parameters.Add("ABFMLMG", OracleType.NVarChar).Value = dwLocal["ABFMLMG"];
                    or1.Parameters.Add("ABFQUALI", OracleType.NVarChar).Value = dwLocal["ABFQUALI"];
                    or1.Parameters.Add("ABFLGRP", OracleType.NVarChar).Value = dwLocal["ABFLGRP"];
                    or1.Parameters.Add("ABFLART", OracleType.NVarChar).Value = dwLocal["ABFLART"];
                    or1.Parameters.Add("ABFLZDR", OracleType.NVarChar).Value = dwLocal["ABFLZDR"];
                    or1.Parameters.Add("ABFPRBMGZT", OracleType.NVarChar).Value = dwLocal["ABFPRBMGZT"];
                    or1.Parameters.Add("ABFZEITLN", OracleType.NVarChar).Value = dwLocal["ABFZEITLN"];
                    or1.Parameters.Add("ABFPENETTO", OracleType.NVarChar).Value = dwLocal["ABFPENETTO"];
                    or1.Parameters.Add("ABFPLKOST", OracleType.NVarChar).Value = dwLocal["ABFPLKOST"];
                    or1.Parameters.Add("ABFLABDIPS", OracleType.NVarChar).Value = dwLocal["ABFLABDIPS"];
                    or1.Parameters.Add("ABFNBREP", OracleType.NVarChar).Value = dwLocal["ABFNBREP"];
                    or1.Parameters.Add("ABFAGENTF", OracleType.NVarChar).Value = dwLocal["ABFAGENTF"];
                    or1.Parameters.Add("ABFBAFOLGE", OracleType.NVarChar).Value = dwLocal["ABFBAFOLGE"];
                    or1.Parameters.Add("ABFVNAME", OracleType.NVarChar).Value = dwLocal["ABFVNAME"];
                    or1.Parameters.Add("ABFFLAG", OracleType.NVarChar).Value = dwLocal["ABFFLAG"];
                    or1.Parameters.Add("ABFEGVNAME1", OracleType.NVarChar).Value = dwLocal["ABFEGVNAME1"];
                    or1.Parameters.Add("ABFEGFLAG1", OracleType.NVarChar).Value = dwLocal["ABFEGFLAG1"];
                    or1.Parameters.Add("ABFEGVNAME2", OracleType.NVarChar).Value = dwLocal["ABFEGVNAME2"];
                    or1.Parameters.Add("ABFEGFLAG2", OracleType.NVarChar).Value = dwLocal["ABFEGFLAG2"];
                    or1.Parameters.Add("ABFEGVNAME3", OracleType.NVarChar).Value = dwLocal["ABFEGVNAME3"];
                    or1.Parameters.Add("ABFEGFLAG3", OracleType.NVarChar).Value = dwLocal["ABFEGFLAG3"];
                    or1.Parameters.Add("ABFEGVNAME4", OracleType.NVarChar).Value = dwLocal["ABFEGVNAME4"];
                    or1.Parameters.Add("ABFEGFLAG4", OracleType.NVarChar).Value = dwLocal["ABFEGFLAG4"];
                    or1.Parameters.Add("ABFEGVNAME5", OracleType.NVarChar).Value = dwLocal["ABFEGVNAME5"];
                    or1.Parameters.Add("ABFEGFLAG5", OracleType.NVarChar).Value = dwLocal["ABFEGFLAG5"];
                    or1.Parameters.Add("ABFMKFS", OracleType.NVarChar).Value = dwLocal["ABFMKFS"];
                    or1.Parameters.Add("ABFMKFI", OracleType.NVarChar).Value = dwLocal["ABFMKFI"];
                    or1.Parameters.Add("ABFMKGS", OracleType.NVarChar).Value = dwLocal["ABFMKGS"];
                    or1.Parameters.Add("ABFMKGI", OracleType.NVarChar).Value = dwLocal["ABFMKGI"];
                    or1.Parameters.Add("ABFMKKS", OracleType.NVarChar).Value = dwLocal["ABFMKKS"];
                    or1.Parameters.Add("ABFMKKI", OracleType.NVarChar).Value = dwLocal["ABFMKKI"];
                    or1.Parameters.Add("ABFMKRWS", OracleType.NVarChar).Value = dwLocal["ABFMKRWS"];
                    or1.Parameters.Add("ABFMKRWI", OracleType.NVarChar).Value = dwLocal["ABFMKRWI"];
                    or1.Parameters.Add("ABFMKFWS", OracleType.NVarChar).Value = dwLocal["ABFMKFWS"];
                    or1.Parameters.Add("ABFMKFWI", OracleType.NVarChar).Value = dwLocal["ABFMKFWI"];
                    or1.Parameters.Add("ABFMKSOS", OracleType.NVarChar).Value = dwLocal["ABFMKSOS"];
                    or1.Parameters.Add("ABFMKSOI", OracleType.NVarChar).Value = dwLocal["ABFMKSOI"];
                    or1.Parameters.Add("ABFMKTS", OracleType.NVarChar).Value = dwLocal["ABFMKTS"];
                    or1.Parameters.Add("ABFMKTI", OracleType.NVarChar).Value = dwLocal["ABFMKTI"];
                    or1.Parameters.Add("ABFMKUS", OracleType.NVarChar).Value = dwLocal["ABFMKUS"];
                    or1.Parameters.Add("ABFMKUI", OracleType.NVarChar).Value = dwLocal["ABFMKUI"];
                    or1.Parameters.Add("ABFMKREZFS", OracleType.NVarChar).Value = dwLocal["ABFMKREZFS"];
                    or1.Parameters.Add("ABFMKREZFI", OracleType.NVarChar).Value = dwLocal["ABFMKREZFI"];
                    or1.Parameters.Add("ABFMKREZCS", OracleType.NVarChar).Value = dwLocal["ABFMKREZCS"];
                    or1.Parameters.Add("ABFMKREZCI", OracleType.NVarChar).Value = dwLocal["ABFMKREZCI"];
                    or1.Parameters.Add("ABFMGKS1", OracleType.NVarChar).Value = dwLocal["ABFMGKS1"];
                    or1.Parameters.Add("ABFMGKS2", OracleType.NVarChar).Value = dwLocal["ABFMGKS2"];
                    or1.Parameters.Add("ABFMGKS3", OracleType.NVarChar).Value = dwLocal["ABFMGKS3"];
                    or1.Parameters.Add("ABFMGKS4", OracleType.NVarChar).Value = dwLocal["ABFMGKS4"];
                    or1.Parameters.Add("ABFMGKS5", OracleType.NVarChar).Value = dwLocal["ABFMGKS5"];
                    or1.Parameters.Add("ABFMGKI1", OracleType.NVarChar).Value = dwLocal["ABFMGKI1"];
                    or1.Parameters.Add("ABFMGKI2", OracleType.NVarChar).Value = dwLocal["ABFMGKI2"];
                    or1.Parameters.Add("ABFMGKI3", OracleType.NVarChar).Value = dwLocal["ABFMGKI3"];
                    or1.Parameters.Add("ABFMGKI4", OracleType.NVarChar).Value = dwLocal["ABFMGKI4"];
                    or1.Parameters.Add("ABFMGKI5", OracleType.NVarChar).Value = dwLocal["ABFMGKI5"];
                    or1.Parameters.Add("ABFFKMS1", OracleType.NVarChar).Value = dwLocal["ABFFKMS1"];
                    or1.Parameters.Add("ABFFKMS2", OracleType.NVarChar).Value = dwLocal["ABFFKMS2"];
                    or1.Parameters.Add("ABFFKMS3", OracleType.NVarChar).Value = dwLocal["ABFFKMS3"];
                    or1.Parameters.Add("ABFFKMS4", OracleType.NVarChar).Value = dwLocal["ABFFKMS4"];
                    or1.Parameters.Add("ABFFKMS5", OracleType.NVarChar).Value = dwLocal["ABFFKMS5"];
                    or1.Parameters.Add("ABFFKMI1", OracleType.NVarChar).Value = dwLocal["ABFFKMI1"];
                    or1.Parameters.Add("ABFFKMI2", OracleType.NVarChar).Value = dwLocal["ABFFKMI2"];
                    or1.Parameters.Add("ABFFKMI3", OracleType.NVarChar).Value = dwLocal["ABFFKMI3"];
                    or1.Parameters.Add("ABFFKMI4", OracleType.NVarChar).Value = dwLocal["ABFFKMI4"];
                    or1.Parameters.Add("ABFFKMI5", OracleType.NVarChar).Value = dwLocal["ABFFKMI5"];
                    or1.Parameters.Add("ABFFKPS1", OracleType.NVarChar).Value = dwLocal["ABFFKPS1"];
                    or1.Parameters.Add("ABFFKPS2", OracleType.NVarChar).Value = dwLocal["ABFFKPS2"];
                    or1.Parameters.Add("ABFFKPS3", OracleType.NVarChar).Value = dwLocal["ABFFKPS3"];
                    or1.Parameters.Add("ABFFKPS4", OracleType.NVarChar).Value = dwLocal["ABFFKPS4"];
                    or1.Parameters.Add("ABFFKPS5", OracleType.NVarChar).Value = dwLocal["ABFFKPS5"];
                    or1.Parameters.Add("ABFFKPI1", OracleType.NVarChar).Value = dwLocal["ABFFKPI1"];
                    or1.Parameters.Add("ABFFKPI2", OracleType.NVarChar).Value = dwLocal["ABFFKPI2"];
                    or1.Parameters.Add("ABFFKPI3", OracleType.NVarChar).Value = dwLocal["ABFFKPI3"];
                    or1.Parameters.Add("ABFFKPI4", OracleType.NVarChar).Value = dwLocal["ABFFKPI4"];
                    or1.Parameters.Add("ABFFKPI5", OracleType.NVarChar).Value = dwLocal["ABFFKPI5"];
                    or1.Parameters.Add("ABFFGKS1", OracleType.NVarChar).Value = dwLocal["ABFFGKS1"];
                    or1.Parameters.Add("ABFFGKS2", OracleType.NVarChar).Value = dwLocal["ABFFGKS2"];
                    or1.Parameters.Add("ABFFGKS3", OracleType.NVarChar).Value = dwLocal["ABFFGKS3"];
                    or1.Parameters.Add("ABFFGKS4", OracleType.NVarChar).Value = dwLocal["ABFFGKS4"];
                    or1.Parameters.Add("ABFFGKS5", OracleType.NVarChar).Value = dwLocal["ABFFGKS5"];
                    or1.Parameters.Add("ABFFGKI1", OracleType.NVarChar).Value = dwLocal["ABFFGKI1"];
                    or1.Parameters.Add("ABFFGKI2", OracleType.NVarChar).Value = dwLocal["ABFFGKI2"];
                    or1.Parameters.Add("ABFFGKI3", OracleType.NVarChar).Value = dwLocal["ABFFGKI3"];
                    or1.Parameters.Add("ABFFGKI4", OracleType.NVarChar).Value = dwLocal["ABFFGKI4"];
                    or1.Parameters.Add("ABFFGKI5", OracleType.NVarChar).Value = dwLocal["ABFFGKI5"];
                    or1.Parameters.Add("ABFFFKS", OracleType.NVarChar).Value = dwLocal["ABFFFKS"];
                    or1.Parameters.Add("ABFFFKI", OracleType.NVarChar).Value = dwLocal["ABFFFKI"];
                    or1.Parameters.Add("ABFIMZT", OracleType.NVarChar).Value = dwLocal["ABFIMZT"];
                    or1.Parameters.Add("ABFIPZT", OracleType.NVarChar).Value = dwLocal["ABFIPZT"];
                    or1.Parameters.Add("ABFIRML", OracleType.NVarChar).Value = dwLocal["ABFIRML"];
                    or1.Parameters.Add("ABFIRMS", OracleType.NVarChar).Value = dwLocal["ABFIRMS"];
                    or1.Parameters.Add("ABFIRPZ", OracleType.NVarChar).Value = dwLocal["ABFIRPZ"];
                    or1.Parameters.Add("ABFBNRZ", OracleType.NVarChar).Value = dwLocal["ABFBNRZ"];
                    or1.Parameters.Add("ABFSCHBSTA", OracleType.NVarChar).Value = dwLocal["ABFSCHBSTA"];
                    or1.Parameters.Add("ABFWARSTA", OracleType.NVarChar).Value = dwLocal["ABFWARSTA"];
                    or1.Parameters.Add("ABFBSMENGE", OracleType.NVarChar).Value = dwLocal["ABFBSMENGE"];
                    or1.Parameters.Add("ABFFBSTA", OracleType.NVarChar).Value = dwLocal["ABFFBSTA"];
                    or1.Parameters.Add("ABFGEBNR", OracleType.NVarChar).Value = dwLocal["ABFGEBNR"];
                    or1.Parameters.Add("ABFBEHNRT", OracleType.NVarChar).Value = dwLocal["ABFBEHNRT"];
                    or1.Parameters.Add("ABFBEHNRN", OracleType.NVarChar).Value = dwLocal["ABFBEHNRN"];
                    or1.Parameters.Add("ABFFBBELO", OracleType.NVarChar).Value = dwLocal["ABFFBBELO"];
                    or1.Parameters.Add("ABFFBBELB", OracleType.NVarChar).Value = dwLocal["ABFFBBELB"];
                    or1.Parameters.Add("ABFFBBELP", OracleType.NVarChar).Value = dwLocal["ABFFBBELP"];
                    or1.Parameters.Add("ABFSTOPSTA", OracleType.NVarChar).Value = dwLocal["ABFSTOPSTA"];
                    or1.Parameters.Add("ABFSTOPGRD", OracleType.NVarChar).Value = dwLocal["ABFSTOPGRD"];
                    or1.Parameters.Add("ABFZUSKZ", OracleType.NVarChar).Value = dwLocal["ABFZUSKZ"];
                    or1.Parameters.Add("ABFERSTKZ", OracleType.NVarChar).Value = dwLocal["ABFERSTKZ"];
                    or1.Parameters.Add("ABFLAEAENDO", OracleType.NVarChar).Value = dwLocal["ABFLAEAENDO"];
                    or1.Parameters.Add("ABFPRUEFGEN", OracleType.NVarChar).Value = dwLocal["ABFPRUEFGEN"];
                    or1.Parameters.Add("ABFCWEIGHT", OracleType.NVarChar).Value = dwLocal["ABFCWEIGHT"];
                    or1.Parameters.Add("ABFRUECKBEN", OracleType.NVarChar).Value = dwLocal["ABFRUECKBEN"];
                    or1.Parameters.Add("ABFKETTANZ", OracleType.NVarChar).Value = dwLocal["ABFKETTANZ"];
                    or1.Parameters.Add("ABFMETHODE", OracleType.NVarChar).Value = dwLocal["ABFMETHODE"];
                    or1.Parameters.Add("ABFRZKZ", OracleType.NVarChar).Value = dwLocal["ABFRZKZ"];
                    or1.Parameters.Add("ABFREWEIL", OracleType.NVarChar).Value = dwLocal["ABFREWEIL"];
                    or1.Parameters.Add("ABFURLAND", OracleType.NVarChar).Value = dwLocal["ABFURLAND"];
                    or1.Parameters.Add("ABFTSDAT", OracleType.NVarChar).Value = dwLocal["ABFTSDAT"];
                    or1.Parameters.Add("ABFTSAFO", OracleType.NVarChar).Value = dwLocal["ABFTSAFO"];
                    or1.Parameters.Add("ABFTEDAT", OracleType.NVarChar).Value = dwLocal["ABFTEDAT"];
                    or1.Parameters.Add("ABFLIMAUZ3", OracleType.NVarChar).Value = dwLocal["ABFLIMAUZ3"];
                    or1.Parameters.Add("ABFLIMIWM3", OracleType.NVarChar).Value = dwLocal["ABFLIMIWM3"];
                    or1.Parameters.Add("ABFLIABS3", OracleType.NVarChar).Value = dwLocal["ABFLIABS3"];
                    or1.Parameters.Add("ABFLIABSZE3", OracleType.NVarChar).Value = dwLocal["ABFLIABSZE3"];
                    or1.Parameters.Add("ABFLIAFOLGE4", OracleType.NVarChar).Value = dwLocal["ABFLIAFOLGE4"];
                    or1.Parameters.Add("ABFLIART4", OracleType.NVarChar).Value = dwLocal["ABFLIART4"];
                    or1.Parameters.Add("ABFLIMIUZ4", OracleType.NVarChar).Value = dwLocal["ABFLIMIUZ4"];
                    or1.Parameters.Add("ABFLIMAUZ4", OracleType.NVarChar).Value = dwLocal["ABFLIMAUZ4"];
                    or1.Parameters.Add("ABFLIMIWM4", OracleType.NVarChar).Value = dwLocal["ABFLIMIWM4"];
                    or1.Parameters.Add("ABFLIABS4", OracleType.NVarChar).Value = dwLocal["ABFLIABS4"];
                    or1.Parameters.Add("ABFLIABSZE4", OracleType.NVarChar).Value = dwLocal["ABFLIABSZE4"];
                    or1.Parameters.Add("ABFLIAFOLGE5", OracleType.NVarChar).Value = dwLocal["ABFLIAFOLGE5"];
                    or1.Parameters.Add("ABFLIART5", OracleType.NVarChar).Value = dwLocal["ABFLIART5"];
                    or1.Parameters.Add("ABFLIMIUZ5", OracleType.NVarChar).Value = dwLocal["ABFLIMIUZ5"];
                    or1.Parameters.Add("ABFLIMAUZ5", OracleType.NVarChar).Value = dwLocal["ABFLIMAUZ5"];
                    or1.Parameters.Add("ABFLIMIWM5", OracleType.NVarChar).Value = dwLocal["ABFLIMIWM5"];
                    or1.Parameters.Add("ABFLIABS5", OracleType.NVarChar).Value = dwLocal["ABFLIABS5"];
                    or1.Parameters.Add("ABFLIABSZE5", OracleType.NVarChar).Value = dwLocal["ABFLIABSZE5"];
                    or1.Parameters.Add("ABFPERSANZ", OracleType.NVarChar).Value = dwLocal["ABFPERSANZ"];
                    or1.Parameters.Add("ABFPERSZE", OracleType.NVarChar).Value = dwLocal["ABFPERSZE"];
                    or1.Parameters.Add("ABFPERSZT", OracleType.NVarChar).Value = dwLocal["ABFPERSZT"];
                    or1.Parameters.Add("ABFPERSMB", OracleType.NVarChar).Value = dwLocal["ABFPERSMB"];
                    or1.Parameters.Add("ABFRUESTZE", OracleType.NVarChar).Value = dwLocal["ABFRUESTZE"];
                    or1.Parameters.Add("ABFRUESTZT", OracleType.NVarChar).Value = dwLocal["ABFRUESTZT"];
                    or1.Parameters.Add("ABFRPERSZT", OracleType.NVarChar).Value = dwLocal["ABFRPERSZT"];
                    or1.Parameters.Add("ABFANZMA", OracleType.NVarChar).Value = dwLocal["ABFANZMA"];
                    or1.Parameters.Add("ABFFAKTOR", OracleType.NVarChar).Value = dwLocal["ABFFAKTOR"];
                    or1.Parameters.Add("ABFFAKTORBLG", OracleType.NVarChar).Value = dwLocal["ABFFAKTORBLG"];
                    or1.Parameters.Add("ABFABEARBZT", OracleType.NVarChar).Value = dwLocal["ABFABEARBZT"];
                    or1.Parameters.Add("ABFARUESTZT", OracleType.NVarChar).Value = dwLocal["ABFARUESTZT"];
                    or1.Parameters.Add("ABFAMASCHZT", OracleType.NVarChar).Value = dwLocal["ABFAMASCHZT"];
                    or1.Parameters.Add("ABFAPERSZT", OracleType.NVarChar).Value = dwLocal["ABFAPERSZT"];
                    or1.Parameters.Add("ABFANZAF", OracleType.NVarChar).Value = dwLocal["ABFANZAF"];
                    or1.Parameters.Add("ABFVERWZE", OracleType.NVarChar).Value = dwLocal["ABFVERWZE"];
                    or1.Parameters.Add("ABFVERWZTV", OracleType.NVarChar).Value = dwLocal["ABFVERWZTV"];
                    or1.Parameters.Add("ABFVERWZTB", OracleType.NVarChar).Value = dwLocal["ABFVERWZTB"];
                    or1.Parameters.Add("ABFVLFZT", OracleType.NVarChar).Value = dwLocal["ABFVLFZT"];
                    or1.Parameters.Add("ABFVLFZTZE", OracleType.NVarChar).Value = dwLocal["ABFVLFZTZE"];
                    or1.Parameters.Add("ABFSOLLSTART", OracleType.NVarChar).Value = dwLocal["ABFSOLLSTART"];
                    or1.Parameters.Add("ABFSOLLDAT", OracleType.NVarChar).Value = dwLocal["ABFSOLLDAT"];
                    or1.Parameters.Add("ABFSOLLSTARTA", OracleType.NVarChar).Value = dwLocal["ABFSOLLSTARTA"];
                    or1.Parameters.Add("ABFSOLLDATA", OracleType.NVarChar).Value = dwLocal["ABFSOLLDATA"];
                    or1.Parameters.Add("ABFFIXTERM", OracleType.NVarChar).Value = dwLocal["ABFFIXTERM"];
                    or1.Parameters.Add("ABFRUECKKZ", OracleType.NVarChar).Value = dwLocal["ABFRUECKKZ"];
                    or1.Parameters.Add("ABFKENNUNG", OracleType.NVarChar).Value = dwLocal["ABFKENNUNG"];
                    or1.Parameters.Add("ABFSONDERKZ", OracleType.NVarChar).Value = dwLocal["ABFSONDERKZ"];
                    or1.Parameters.Add("ABFZUSATZ1", OracleType.NVarChar).Value = dwLocal["ABFZUSATZ1"];
                    or1.Parameters.Add("ABFZUSATZ2", OracleType.NVarChar).Value = dwLocal["ABFZUSATZ2"];
                    or1.Parameters.Add("ABFZUSATZ3", OracleType.NVarChar).Value = dwLocal["ABFZUSATZ3"];
                    or1.Parameters.Add("ABFZUSATZ4", OracleType.NVarChar).Value = dwLocal["ABFZUSATZ4"];
                    or1.Parameters.Add("ABFZUSATZ5", OracleType.NVarChar).Value = dwLocal["ABFZUSATZ5"];
                    or1.Parameters.Add("ABFFZUSATZKZ1", OracleType.NVarChar).Value = dwLocal["ABFFZUSATZKZ1"];
                    or1.Parameters.Add("ABFFZUSATZKZ2", OracleType.NVarChar).Value = dwLocal["ABFFZUSATZKZ2"];
                    or1.Parameters.Add("ABFFZUSATZKZ3", OracleType.NVarChar).Value = dwLocal["ABFFZUSATZKZ3"];
                    or1.Parameters.Add("ABFFZUSATZKZ4", OracleType.NVarChar).Value = dwLocal["ABFFZUSATZKZ4"];
                    or1.Parameters.Add("ABFFZUSATZKZ5", OracleType.NVarChar).Value = dwLocal["ABFFZUSATZKZ5"];
                    or1.Parameters.Add("ABFZUSTAND", OracleType.NVarChar).Value = dwLocal["ABFZUSTAND"];
                    or1.Parameters.Add("ABFFERTIG", OracleType.NVarChar).Value = dwLocal["ABFFERTIG"];
                    or1.Parameters.Add("ABFMATABR", OracleType.NVarChar).Value = dwLocal["ABFMATABR"];
                    or1.Parameters.Add("ABFDOMPART", OracleType.NVarChar).Value = dwLocal["ABFDOMPART"];
                    or1.Parameters.Add("ABFLAGPLKZ", OracleType.NVarChar).Value = dwLocal["ABFLAGPLKZ"];
                    or1.Parameters.Add("ABFLO", OracleType.NVarChar).Value = dwLocal["ABFLO"];
                    or1.Parameters.Add("ABFLB", OracleType.NVarChar).Value = dwLocal["ABFLB"];
                    or1.Parameters.Add("ABFLP", OracleType.NVarChar).Value = dwLocal["ABFLP"];
                    or1.Parameters.Add("ABFAUFBKZ", OracleType.NVarChar).Value = dwLocal["ABFAUFBKZ"];
                    or1.Parameters.Add("ABFPRUEFANW", OracleType.NVarChar).Value = dwLocal["ABFPRUEFANW"];
                    or1.Parameters.Add("ABFPROBE", OracleType.NVarChar).Value = dwLocal["ABFPROBE"];
                    or1.Parameters.Add("ABFSPSTA", OracleType.NVarChar).Value = dwLocal["ABFSPSTA"];
                    or1.Parameters.Add("ABFSPGRD", OracleType.NVarChar).Value = dwLocal["ABFSPGRD"];
                    or1.Parameters.Add("ABFMEKOPFKZ", OracleType.NVarChar).Value = dwLocal["ABFMEKOPFKZ"];
                    or1.Parameters.Add("ABFSTATUS", OracleType.NVarChar).Value = dwLocal["ABFSTATUS"];
                    or1.Parameters.Add("ABFRUECKMKZ", OracleType.NVarChar).Value = dwLocal["ABFRUECKMKZ"];
                    or1.Parameters.Add("ABFRAFOLGE", OracleType.NVarChar).Value = dwLocal["ABFRAFOLGE"];
                    or1.Parameters.Add("ABFRUECKDAT", OracleType.NVarChar).Value = dwLocal["ABFRUECKDAT"];
                    or1.Parameters.Add("ABFRUECKZT", OracleType.NVarChar).Value = dwLocal["ABFRUECKZT"];
                    or1.Parameters.Add("ABFIMNRKRS", OracleType.NVarChar).Value = dwLocal["ABFIMNRKRS"];
                    or1.Parameters.Add("ABFIMLFDNR", OracleType.NVarChar).Value = dwLocal["ABFIMLFDNR"];
                    or1.Parameters.Add("ABFIMPOS", OracleType.NVarChar).Value = dwLocal["ABFIMPOS"];
                    or1.Parameters.Add("ABFISTK", OracleType.NVarChar).Value = dwLocal["ABFISTK"];
                    or1.Parameters.Add("ABFIMG", OracleType.NVarChar).Value = dwLocal["ABFIMG"];
                    or1.Parameters.Add("ABFIMTR", OracleType.NVarChar).Value = dwLocal["ABFIMTR"];
                    or1.Parameters.Add("ABFIDIFFMG", OracleType.NVarChar).Value = dwLocal["ABFIDIFFMG"];
                    or1.Parameters.Add("ABFISTARTDAT", OracleType.NVarChar).Value = dwLocal["ABFISTARTDAT"];
                    or1.Parameters.Add("ABFISTARTZT", OracleType.NVarChar).Value = dwLocal["ABFISTARTZT"];
                    or1.Parameters.Add("ABFIENDDAT", OracleType.NVarChar).Value = dwLocal["ABFIENDDAT"];
                    or1.Parameters.Add("ABFIENDZT", OracleType.NVarChar).Value = dwLocal["ABFIENDZT"];
                    or1.Parameters.Add("ABFANZTLG", OracleType.NVarChar).Value = dwLocal["ABFANZTLG"];
                    or1.Parameters.Add("ABFRETOURKZ", OracleType.NVarChar).Value = dwLocal["ABFRETOURKZ"];
                    or1.Parameters.Add("ABFREAUFKRS", OracleType.NVarChar).Value = dwLocal["ABFREAUFKRS"];
                    or1.Parameters.Add("ABFREAUFLFD", OracleType.NVarChar).Value = dwLocal["ABFREAUFLFD"];
                    or1.Parameters.Add("ABFREAUFPOS", OracleType.NVarChar).Value = dwLocal["ABFREAUFPOS"];
                    or1.Parameters.Add("ABFSTUFE", OracleType.NVarChar).Value = dwLocal["ABFSTUFE"];
                    or1.Parameters.Add("ABFWERK", OracleType.NVarChar).Value = dwLocal["ABFWERK"];
                    or1.Parameters.Add("ABFANRKRS", OracleType.NVarChar).Value = dwLocal["ABFANRKRS"];
                    or1.Parameters.Add("ABFALFDNR", OracleType.NVarChar).Value = dwLocal["ABFALFDNR"];
                    or1.Parameters.Add("ABFSAFOLGE", OracleType.NVarChar).Value = dwLocal["ABFSAFOLGE"];
                    or1.Parameters.Add("ABFAEVOR", OracleType.NVarChar).Value = dwLocal["ABFAEVOR"];
                    or1.Parameters.Add("ABFEINSTKA", OracleType.NVarChar).Value = dwLocal["ABFEINSTKA"];
                    or1.Parameters.Add("ABFBANRKRS", OracleType.NVarChar).Value = dwLocal["ABFBANRKRS"];
                    or1.Parameters.Add("ABFBALFDNR", OracleType.NVarChar).Value = dwLocal["ABFBALFDNR"];
                    or1.Parameters.Add("ABFEVARHNR", OracleType.NVarChar).Value = dwLocal["ABFEVARHNR"];
                    or1.Parameters.Add("ABFEVARUNR", OracleType.NVarChar).Value = dwLocal["ABFEVARUNR"];
                    or1.Parameters.Add("ABFRUESTFAM", OracleType.NVarChar).Value = dwLocal["ABFRUESTFAM"];
                    or1.Parameters.Add("ABFBNRKRS", OracleType.NVarChar).Value = dwLocal["ABFBNRKRS"];
                    or1.Parameters.Add("ABFBLFDNR", OracleType.NVarChar).Value = dwLocal["ABFBLFDNR"];
                    or1.Parameters.Add("ABFBPOS", OracleType.NVarChar).Value = dwLocal["ABFBPOS"];
                    or1.Parameters.Add("ABFVONMOD", OracleType.NVarChar).Value = dwLocal["ABFVONMOD"];
                    or1.Parameters.Add("ABFBISMOD", OracleType.NVarChar).Value = dwLocal["ABFBISMOD"];
                    or1.Parameters.Add("ABFBLOCKKZ1", OracleType.NVarChar).Value = dwLocal["ABFBLOCKKZ1"];
                    or1.Parameters.Add("ABFBLOCKKZ2", OracleType.NVarChar).Value = dwLocal["ABFBLOCKKZ2"];
                    or1.Parameters.Add("ABFPAPIERKZ", OracleType.NVarChar).Value = dwLocal["ABFPAPIERKZ"];
                    or1.Parameters.Add("ABFKALKKZ", OracleType.NVarChar).Value = dwLocal["ABFKALKKZ"];
                    or1.Parameters.Add("ABFALTKSTKZ", OracleType.NVarChar).Value = dwLocal["ABFALTKSTKZ"];
                    or1.Parameters.Add("ABFBDEKEN", OracleType.NVarChar).Value = dwLocal["ABFBDEKEN"];
                    or1.Parameters.Add("ABFPRIO", OracleType.NVarChar).Value = dwLocal["ABFPRIO"];
                    or1.Parameters.Add("ABFSTATKZ", OracleType.NVarChar).Value = dwLocal["ABFSTATKZ"];
                    or1.Parameters.Add("ABFPROZMG", OracleType.NVarChar).Value = dwLocal["ABFPROZMG"];
                    or1.Parameters.Add("ABFAENDZL", OracleType.NVarChar).Value = dwLocal["ABFAENDZL"];
                    or1.Parameters.Add("ABFAENDBEN", OracleType.NVarChar).Value = dwLocal["ABFAENDBEN"];
                    or1.Parameters.Add("ABFAENDDAT", OracleType.NVarChar).Value = dwLocal["ABFAENDDAT"];
                    or1.Parameters.Add("ABFNEUBEN", OracleType.NVarChar).Value = dwLocal["ABFNEUBEN"];
                    or1.Parameters.Add("ABFNEUDAT", OracleType.NVarChar).Value = dwLocal["ABFNEUDAT"];
                    or1.Parameters.Add("ABFPLANKZ", OracleType.NVarChar).Value = dwLocal["ABFPLANKZ"];
                    or1.Parameters.Add("ABFKSTKRS", OracleType.NVarChar).Value = dwLocal["ABFKSTKRS"];
                    or1.Parameters.Add("ABFKST", OracleType.NVarChar).Value = dwLocal["ABFKST"];
                    or1.Parameters.Add("ABFSPLPOS", OracleType.NVarChar).Value = dwLocal["ABFSPLPOS"];
                    or1.Parameters.Add("ABFAGANG", OracleType.NVarChar).Value = dwLocal["ABFAGANG"];
                    or1.Parameters.Add("ABFBZAGANG", OracleType.NVarChar).Value = dwLocal["ABFBZAGANG"];
                    or1.Parameters.Add("ABFMTYP", OracleType.NVarChar).Value = dwLocal["ABFMTYP"];
                    or1.Parameters.Add("ABFLIEFNR", OracleType.NVarChar).Value = dwLocal["ABFLIEFNR"];
                    or1.Parameters.Add("ABFMNRKRS", OracleType.NVarChar).Value = dwLocal["ABFMNRKRS"];
                    or1.Parameters.Add("ABFMLFDNR", OracleType.NVarChar).Value = dwLocal["ABFMLFDNR"];
                    or1.Parameters.Add("ABFMPOS", OracleType.NVarChar).Value = dwLocal["ABFMPOS"];
                    or1.Parameters.Add("ABFMPLPOS", OracleType.NVarChar).Value = dwLocal["ABFMPLPOS"];
                    or1.Parameters.Add("ABFMANUELKZ", OracleType.NVarChar).Value = dwLocal["ABFMANUELKZ"];
                    or1.Parameters.Add("ABFPARALKZ", OracleType.NVarChar).Value = dwLocal["ABFPARALKZ"];
                    or1.Parameters.Add("ABFSOLLSTK", OracleType.NVarChar).Value = dwLocal["ABFSOLLSTK"];
                    or1.Parameters.Add("ABFSOLLMG", OracleType.NVarChar).Value = dwLocal["ABFSOLLMG"];
                    or1.Parameters.Add("ABFSOLLME", OracleType.NVarChar).Value = dwLocal["ABFSOLLME"];
                    or1.Parameters.Add("ABFSOLLMTR", OracleType.NVarChar).Value = dwLocal["ABFSOLLMTR"];
                    or1.Parameters.Add("ABFLAEAEND", OracleType.NVarChar).Value = dwLocal["ABFLAEAEND"];
                    or1.Parameters.Add("ABFGEWAEND", OracleType.NVarChar).Value = dwLocal["ABFGEWAEND"];
                    or1.Parameters.Add("ABFBASMGE", OracleType.NVarChar).Value = dwLocal["ABFBASMGE"];
                    or1.Parameters.Add("ABFME", OracleType.NVarChar).Value = dwLocal["ABFME"];
                    or1.Parameters.Add("ABFFIX", OracleType.NVarChar).Value = dwLocal["ABFFIX"];
                    or1.Parameters.Add("ABFAGRVON", OracleType.NVarChar).Value = dwLocal["ABFAGRVON"];
                    or1.Parameters.Add("ABFAGRBIS", OracleType.NVarChar).Value = dwLocal["ABFAGRBIS"];
                    or1.Parameters.Add("ABFMASCHANZ", OracleType.NVarChar).Value = dwLocal["ABFMASCHANZ"];
                    or1.Parameters.Add("ABFMASCHZE", OracleType.NVarChar).Value = dwLocal["ABFMASCHZE"];
                    or1.Parameters.Add("ABFMASCHZT", OracleType.NVarChar).Value = dwLocal["ABFMASCHZT"];
                    or1.Parameters.Add("ABFLIAFOLGE1", OracleType.NVarChar).Value = dwLocal["ABFLIAFOLGE1"];
                    or1.Parameters.Add("ABFLIART1", OracleType.NVarChar).Value = dwLocal["ABFLIART1"];
                    or1.Parameters.Add("ABFLIMIUZ1", OracleType.NVarChar).Value = dwLocal["ABFLIMIUZ1"];
                    or1.Parameters.Add("ABFLIMAUZ1", OracleType.NVarChar).Value = dwLocal["ABFLIMAUZ1"];
                    or1.Parameters.Add("ABFLIMIWM1", OracleType.NVarChar).Value = dwLocal["ABFLIMIWM1"];
                    or1.Parameters.Add("ABFLIABS1", OracleType.NVarChar).Value = dwLocal["ABFLIABS1"];
                    or1.Parameters.Add("ABFLIABSZE1", OracleType.NVarChar).Value = dwLocal["ABFLIABSZE1"];
                    or1.Parameters.Add("ABFLIAFOLGE2", OracleType.NVarChar).Value = dwLocal["ABFLIAFOLGE2"];
                    or1.Parameters.Add("ABFLIART2", OracleType.NVarChar).Value = dwLocal["ABFLIART2"];
                    or1.Parameters.Add("ABFLIMIUZ2", OracleType.NVarChar).Value = dwLocal["ABFLIMIUZ2"];
                    or1.Parameters.Add("ABFLIMAUZ2", OracleType.NVarChar).Value = dwLocal["ABFLIMAUZ2"];
                    or1.Parameters.Add("ABFLIMIWM2", OracleType.NVarChar).Value = dwLocal["ABFLIMIWM2"];
                    or1.Parameters.Add("ABFLIABS2", OracleType.NVarChar).Value = dwLocal["ABFLIABS2"];
                    or1.Parameters.Add("ABFLIABSZE2", OracleType.NVarChar).Value = dwLocal["ABFLIABSZE2"];
                    or1.Parameters.Add("ABFLIAFOLGE3", OracleType.NVarChar).Value = dwLocal["ABFLIAFOLGE3"];
                    or1.Parameters.Add("ABFLIART3", OracleType.NVarChar).Value = dwLocal["ABFLIART3"];
                    or1.Parameters.Add("ABFLIMIUZ3", OracleType.NVarChar).Value = dwLocal["ABFLIMIUZ3"];
                    setResult = Connect2Proxy(or1);
                    setReturn.Merge(setResult);
                    #endregion
                }
                #region============SELECT==========================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM ABFOLGE "
                + " WHERE ABFMANDANT=:ABFMANDANT AND ABFAUFKRS=:ABFAUFKRS AND ABFAUFLFD= :ABFAUFLFD AND ABFAUFPOS= :ABFAUFPOS";

                or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwLocal["ABFMANDANT"];
                or1.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = dwLocal["ABFAUFKRS"];
                or1.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = dwLocal["ABFAUFLFD"];
                or1.Parameters.Add("ABFAUFPOS", OracleType.NVarChar).Value = dwLocal["ABFAUFPOS"];
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "ABFOLGE";
                }
                setReturn.Merge(setResult);
                #endregion

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }


        public void DeleteABON(string krs, string lfd, string pos, string company = "DST")
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            OracleCommand or1;
            try
            {
                DataRow dwData = INTEXDB.ABAUFM.NewRow();
                dwData["ABAMANDANT"] = "00";
                dwData["ABAAUFKRS"] = krs;
                dwData["ABAAUFLFD"] = lfd;
                dwData["ABAAUFPOS"] = pos;
                setResult = INTEXDBC.QueryABAUFM(dwData, 1);
                if (setResult.Tables[0].Rows.Count == 0)
                    return;
                foreach (DataRow dwABAUFM in setResult.Tables[0].Rows)
                {
                    or1 = OracleDB.CreateCommand();
                    string akrs = dwABAUFM["ABAAUFKRS"].ToString();
                    string alfd = dwABAUFM["ABAAUFLFD"].ToString();
                    string apos = dwABAUFM["ABAAUFPOS"].ToString();
                    or1.CommandText = "DELETE_ORDER_NETWORK";
                    or1.CommandType = CommandType.StoredProcedure;
                    or1.Parameters.Add("AUFKRS", OracleType.NVarChar).Value = akrs;
                    or1.Parameters.Add("AUFLFD", OracleType.NVarChar).Value = alfd;
                    or1.Parameters.Add("AUFPOS", OracleType.NVarChar).Value = apos;
                    Connect2Proxy(or1);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public DataSet LoadJob()
        {
            DataSet SReturn = new DataSet();
            try
            {
                bool last = true;
                DataSet SResult = GetJob(ref last);
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet GetJob(ref  bool last)
        {
            DataSet SResult = new DataSet();
            DataSet SReturn = new DataSet();

            try
            {
                string fileDone;
                string filestemp = @"C:\IntexReport\Data\JLTAV95\01Temp";
                string[] files = System.IO.Directory.GetFiles(filestemp);
                foreach (string file in files)
                {
                    fileDone = file.Replace(@"\01Temp\", @"\02Incoming\");
                    System.IO.File.Move(file, fileDone);
                }
                string files2p = @"C:\IntexReport\Data\JLTAV95\02Incoming";
                files = System.IO.Directory.GetFiles(files2p);

                if (files.Length > 0)
                {
                    string file = files[0];
                    SResult.ReadXml(file);
                    SReturn.Merge(SResult);
                    fileDone = file.Replace(@"\02Incoming\", @"\03Done\");
                    System.IO.File.Move(file, fileDone);
                }
                if (files.Length == 1)
                    last = true;
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {

            }
            return SReturn;
        }
        public void SaveJob()
        {
            DataSet Set = LoadJob();
            if (Set.Tables.Count > 0)
            {
                JobQueue.Enqueue(Set);
            }
            else
            {
                return;
            }
            if (IsRun)
            {
                return;
            }
            if (!IsRun)
            {
                bgWorker.RunWorkerAsync();
            }
        }
        public void AutoRun()
        {

            try
            {
                while (true)
                {
                    if (JobQueue.Count > 0)
                    {
                        SetJob = JobQueue.Dequeue();
                        ConvertToIntex();
                        SaveJob();//loadjob
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                IsRun = false;
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        public bool Upload2Intex()
        {
            bool result = true;
            try
            {
                if (m_wintex == null)
                {
                    m_wintex = new JLTAB2INTEX(OracleDB, proxy);
                }
                m_wintex.ReSet(Set4ITX, null);
                m_wintex.Execute(null);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
                EventDispatcher.Instance.RaiseStatus("异常停止", StatusEventType.StopProgress);
            }
            finally
            {

            }
            return result;
        }
        public void AB2ON(SETINTEXDB src)
        {
            DataSet SetTmp = new DataSet();
            DataSet SReturn = new DataSet();
            try
            {
                string xml = @"C:\IntexReport\Data\JLTAV95\01Temp\AV" + DateTime.Now.ToFileTime().ToString() + ".XML";
                if (src.Tables.Contains("ABPOS_EXT"))
                {
                    src.Tables.Remove("ABPOS_EXT");
                }
                if (src.Tables.Contains("ABPOS"))
                {
                    DataTable TB = src.Tables["ABPOS"].Copy();
                    TB.TableName = "ABPOS_EXT";
                    src.Merge(TB);
                }
                src.WriteXml(xml);
                SaveJob();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        #endregion

        /// <summary>
        /// 1.自动生产生产单所需要的必要数据
        /// 2.利用ICC_ABAUFM表明生产单之间的计划关系
        /// 3.产生原料需求单
        /// </summary>
        /// <param name="dwInput"></param>
        /// <param name="src"></param>
        /// <returns></returns>
        public DataSet PrePlan(DataRow dwVKPOS)
        {
            //此时的环境是该基于内存的环境，整个销售单的数据

            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            string krs = "", lfd, pos;
            DataRow dwABAN;
            try
            {
                string filter = "";
                DataRow[] rows;
                DataRow dwVKWDECK = null;
                filter = "WDAUFKRS='" + dwVKPOS["VKPAUFKRS"].ToString() + "' AND WDAUFLFD='"
                    + dwVKPOS["VKPAUFLFD"].ToString() + "' AND WDAUFPOS='" + dwVKPOS["VKPAUFPOS"].ToString() + "' AND WDSA='K' AND WDUPOS='00'";
                rows = SetData.WDECK.Select(filter);
                foreach (DataRow row in rows)
                {
                    dwVKWDECK = row;
                }
                //根据需求创建对应生产单信息，并且表达计划对应关系
                tbABAUFM = INTEXDB.ICC_ABAUFM.Clone();
                dwABAN = tbABAUFM.NewRow();
                dwABAN["ABAID"] = ABAID;
                dwABAN["ABAVKAUFTYP"] = dwVKWDECK["WDSA"];
                dwABAN["ABAVKAUFKRS"] = dwVKWDECK["WDAUFKRS"];
                dwABAN["ABAVKAUFLFD"] = dwVKWDECK["WDAUFLFD"];
                dwABAN["ABAVKAUFPOS"] = dwVKWDECK["WDAUFPOS"];
                dwABAN["ABAVKUPOS"] = dwVKWDECK["WDUPOS"];
                if (dwABAN["ABAVKUPOS"].ToString().Trim() == "00")
                {
                    dwABAN["ABAVKUPOS"] = "01";
                }
                dwABAN["ABAVB"] = dwVKWDECK["VKPVB"];
                dwABAN["ABAVG"] = dwVKWDECK["VKPVG"];
                dwABAN["ABARVSACHB"] = dwVKWDECK["VKPSACHBE"];
                dwABAN["ABAVLSACHB"] = dwVKWDECK["VKPSACHBE"];
                dwABAN["ABARKUNDNR"] = dwVKWDECK["VKPKUNDNR"];
                dwABAN["ABAVLVB"] = dwVKWDECK["VKPVB"];
                dwABAN["ABAVLVG"] = dwVKWDECK["VKPVG"];

                dwABAN["ABAAUFMSL"] = dwVKWDECK["VKPAUFMART"];
                dwABAN["ABASSTKLG"] = dwVKWDECK["VKPLAEVON"];

                dwABAN["ABASANZSTK"] = 0;
                dwABAN["ABPWAKZ"] = dwVKWDECK["WDWAKZ"];
                dwABAN["ABPART"] = dwVKWDECK["WDART"];
                dwABAN["ABPVAR"] = dwVKWDECK["WDVAR"];
                dwABAN["ABPFARBE"] = dwVKWDECK["WDFARBE"];
                dwABAN["ABPBESCHICH"] = dwVKWDECK["WDBESCHICH"];
                dwABAN["ABARESMG"] = dwVKWDECK["WDBEDARF"];
                dwABAN["ABAVKENDD"] = dwVKWDECK["WDDAT"];
                dwABAN["ABAVKSTARTD"] = dwVKWDECK["WDDAT"];
                dwABAN["ABAUSER"] = UserID;
                dwABAN["ABADATE"] = date;
                tbABAUFM.Rows.Add(dwABAN);
                ABAID++;
                SResult = PlanAB05(dwABAN);
                SReturn.Merge(SResult);
                filter = "ABAAUFTYP='N' AND ABAWAKZ='R'";
                rows = tbABAUFM.Copy().Select(filter);
                foreach (DataRow row in rows)
                {
                    SResult = PlanAB55(row);
                    SReturn.Merge(SResult);
                }
                filter = "ABAAUFTYP='N' AND ABAWAKZ='W'";
                rows = tbABAUFM.Copy().Select(filter);
                foreach (DataRow row in rows)
                {
                    SResult = PlanAB45(row);
                    SReturn.Merge(SResult);
                }
                filter = "ABAAUFTYP='N' AND ABAWAKZ='G'";
                rows = tbABAUFM.Copy().Select(filter);
                foreach (DataRow row in rows)
                {
                    SResult = PlanAB50(row);
                    SReturn.Merge(SResult);
                }
                SReturn.Merge(tbABAUFM);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }

        /// <summary>
        /// 1.自动生产生产单所需要的必要数据
        /// 2.利用ICC_ABAUFM表明生产单之间的计划关系
        /// 3.产生原料需求单
        /// </summary>
        /// <param name="dwInput"></param>
        /// <param name="src"></param>
        /// <returns></returns>
        public DataSet PlanAB05(DataRow dwABA, DataRow dwProc = null)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataTable tmpABPOS = SetData.ABPOS.Clone();
            DataTable tmpWDECK = SetData.WDECK.Clone();
            string filter = "";
            string ENDD = "";
            string STARTD = "";
            decimal GLeng = 0;
            DataRow[] rows = null;
            DataRow dwWASTAMM = null;
            string KRS = "", LFD = "", POS = "";
            string ART = "";
            string VAR = "";
            string WAKZ = "";
            string FARBE = "";
            string FINISH = "";
            string UM = "米";
            decimal FLeng = 0;
            DataRow dwAPZUORD = null;
            string APZANRKRS = "";
            string APZALFDNR = "";
            DataRow dwABPN = null;
            #region========Validate=================
            KRS = dwABA["ABAVKAUFKRS"].ToString();
            LFD = dwABA["ABAVKAUFLFD"].ToString();
            POS = dwABA["ABAVKAUFPOS"].ToString();
            filter = "WDAUFKRS='" + KRS + "' AND WDAUFLFD='" + LFD
                + "' AND WDAUFPOS='" + POS + "'  AND WDSA='K' AND WDUPOS='00'";
            rows = SetData.WASTAMM.Select(filter);
            foreach (DataRow row in rows)
            {
                dwWASTAMM = row;
            }
            if (dwWASTAMM == null)
            {
                throw new System.Exception("没有对应的工艺档案");
                return SReturn;
            }
            ART = dwABA["ABPART"].ToString();
            VAR = dwABA["ABPVAR"].ToString();
            WAKZ = dwABA["ABPWAKZ"].ToString();
            FARBE = dwABA["ABPFARBE"].ToString();
            FINISH = dwABA["ABPBESCHICH"].ToString();
            dwAPZUORD = dwProc;
            if (dwProc == null)
            {
                filter = "APZSTUFE='F' AND APZART='" + ART
                    + "' AND APZVAR='" + VAR + "' ";
                rows = SetData.APZUORD.Select(filter);
                foreach (DataRow row in rows)
                {
                    dwAPZUORD = row;
                }
            }
            if (dwAPZUORD == null)
            {
                throw new System.Exception("没有对应的工艺流程");
                return SReturn;
            }
            APZANRKRS = dwAPZUORD["APZANRKRS"].ToString();
            APZALFDNR = dwAPZUORD["APZALFDNR"].ToString();
            filter = "APFANRKRS='" + APZANRKRS + "' AND APFALFDNR='" + APZALFDNR + "'";
            rows = SetData.APFOLGE.Select(filter);
            foreach (DataRow row in rows)
            {
                PRLO = row["KSZLO"].ToString();
                PRLB = row["KSZLB"].ToString();
                PRLP = row["KSZLP"].ToString();
            }

            decimal WARSTDLG = Convert.ToDecimal(dwWASTAMM["WARSTDLG"].ToString());
            decimal WALAEAEND = System.Convert.ToDecimal(dwWASTAMM["WALAEAEND"].ToString());
            UM = dwWASTAMM["WAUEBM"].ToString();
            decimal WAFBRTL = System.Convert.ToDecimal(dwWASTAMM["WAFBRTL"].ToString());
            decimal WARGRLFD = System.Convert.ToDecimal(dwWASTAMM["WARGRLFD"].ToString());
            decimal WAFGRLFD = System.Convert.ToDecimal(dwWASTAMM["WAFGRLFD"].ToString());
            decimal WAFSTDLG = System.Convert.ToDecimal(dwWASTAMM["WAFSTDLG"].ToString());
            decimal WARWBRT = System.Convert.ToDecimal(dwWASTAMM["WARWBRT"].ToString());
            if (WAFSTDLG == 0)
            {
                WAFSTDLG = 100000;
            }
            FLeng = Math.Round(Convert.ToDecimal(dwABA["ABARESMG"].ToString()) * Convert.ToDecimal(0.01), 0);
            GLeng = System.Math.Round(FLeng / (1 + WALAEAEND * Convert.ToDecimal(0.0001)), 0);
            ENDD = dwABA["ABAVKSTARTD"].ToString();
            STARTD = GetDateAddDays(ENDD, Convert.ToInt16(0 - LDAB05));
            if (STARTD.Trim() == "") STARTD = "0";
            #endregion
            #region=======dwABPN==========
            dwABPN = tmpABPOS.NewRow();
            dwABPN["ABPMANDANT"] = "00";
            dwABPN["ABPAUFART"] = "VA";
            dwABPN["ABPAUFKRS"] = "T6";
            dwABPN["ABPAUFLFD"] = ABPLFD;
            dwABPN["ABPAUFPOS"] = ABPOS; ABPOS++;
            dwABPN["ABPANRKR"] = APZANRKRS;
            dwABPN["ABPALFDNR"] = APZALFDNR;
            dwABPN["ABPSERIE"] = " ";
            dwABPN["ABPART"] = ART;
            dwABPN["ABPVAR"] = VAR;
            dwABPN["ABPWAKZ"] = WAKZ;
            dwABPN["ABPFARBE"] = FARBE;
            dwABPN["ABPWAART"] = "   ";
            dwABPN["ABPBESCHICH"] = FINISH;
            dwABPN["ABPDIVARTKZ"] = "N";
            dwABPN["ABPLIEFDAT"] = ENDD;
            dwABPN["ABPGESSTA"] = "TE";
            dwABPN["ABPWBSTA"] = "68";
            dwABPN["ABPKETTAUFT"] = " ";
            dwABPN["ABPMGV"] = 0;
            dwABPN["ABPMGB"] = 99999999;
            dwABPN["ABPTMCOUNT"] = 4;            
            dwABPN["ABPSTARTDAT"] = STARTD;
            dwABPN["ABPZUTART"] = 1;
            dwABPN["ABPFA"] = 1;
            dwABPN["ABPGA"] = 100;
            dwABPN["ABPQA"] = 100;
            dwABPN["ABPREGEL"] = "00000007";
            dwABPN["ABPZUSATZ1"] = "F";
            dwABPN["ABPZUSATZ2"] = "B";
            dwABPN["ABPAESTAT"] = "J";

            dwABPN["ABPSTDLAE"] = Convert.ToDecimal(dwWASTAMM["WARSTDLG"].ToString()) / 10;
            dwABPN["ABPZLO"] = PRLO;
            dwABPN["ABPZLB"] = PRLB;
            //dwABPN["ABPBLO"] = PRLO;
            dwABPN["ABPLAEAENDA"] = dwWASTAMM["WALAEAEND"];
            dwABPN["ABPSME"] = 2;
            dwABPN["ABPVFAUFKRS"] = 1;
            dwABPN["ABPAUFST"] = 8;

            dwABPN["ABPSOLLMENGE1"] = GLeng * 100;
            dwABPN["ABPSOLLMENGE2"] = FLeng * 100;
            dwABPN["ABPSOLLMENGE3"] = 100 * Math.Round(GLeng * WARWBRT * Convert.ToDecimal(0.001));
            dwABPN["ABPSOLLMENGE4"] = 100 * Math.Round(FLeng * WAFBRTL * Convert.ToDecimal(0.001));
            dwABPN["ABPSOLLMENGE5"] = 100 * Math.Round(GLeng * WARGRLFD * Convert.ToDecimal(0.001));
            dwABPN["ABPSOLLMENGE6"] = 100 * Math.Round(FLeng * WAFGRLFD * Convert.ToDecimal(0.001));
            dwABPN["ABPSOLLMENGE7"] = 100 * Math.Ceiling(FLeng / (WAFSTDLG * Convert.ToDecimal(0.001)));
            dwABPN["ABPSOLLMENGE8"] = 100 * Math.Ceiling(GLeng / (WARSTDLG * Convert.ToDecimal(0.001)));
            dwABPN["ABPSZUSATZKZ1"] = "F";
            dwABPN["ABPANZSTK"] = 0;
            dwABPN["ABPZUGETGES"] = 0;
            dwABPN["ABPSTKLG"] = 0;
            dwABPN["ABPNEUBEN"] = UserID;
            dwABPN["ABPNEUDAT"] = date; ;
            tmpABPOS.Rows.Add(dwABPN);
            SReturn.Merge(tmpABPOS);
            #endregion
            #region=======ICC_ABAUFM ================
            var query = from DataRow row in tbABAUFM.AsEnumerable()
                        where row["ABAID"].ToString() == dwABA["ABAID"].ToString()
                        select row;
            foreach (DataRow row in query)
            {
                row["ABAAUFTYP"] = "V";
                row["ABAAUFKRS"] = dwABPN["ABPAUFKRS"];
                row["ABAAUFLFD"] = dwABPN["ABPAUFLFD"];
                row["ABAAUFPOS"] = dwABPN["ABPAUFPOS"];
                row["ABAQTYRESERVE"] = FLeng;
                decimal VKPLAEBIS = System.Convert.ToDecimal(row["ABASSTKLG"].ToString()) * 10;
                if (VKPLAEBIS == 0)
                    VKPLAEBIS = 1;
                decimal ABASGESLG = Convert.ToDecimal(dwABPN["ABPSOLLMENGE2"].ToString()) * 10;
                decimal ABASANZSTK = Math.Round(System.Convert.ToDecimal(ABASGESLG) / VKPLAEBIS, 0);
                decimal ABASSTKLG = 0;

                row["ABASANZSTK"] = System.Math.Round(ABASANZSTK, 0);
                ABASSTKLG = VKPLAEBIS;
                row["ABASSTKLG"] = ABASSTKLG;

            }
            //产生下层需求
            DataRow dwABAN = tbABAUFM.NewRow();
            dwABAN["ABAID"] = ABAID;
            dwABAN["ABAAUFTYP"] = "N";
            dwABAN["ABAVKAUFTYP"] = "V";
            dwABAN["ABAVKAUFKRS"] = dwABPN["ABPAUFKRS"];
            dwABAN["ABAVKAUFLFD"] = dwABPN["ABPAUFLFD"];
            dwABAN["ABAVKAUFPOS"] = dwABPN["ABPAUFPOS"];
            dwABAN["ABAVKUPOS"] = "01";
            dwABAN["ABPWAKZ"] = "F";
            dwABAN["ABPART"] = ART;
            dwABAN["ABPVAR"] = VAR;
            dwABAN["ABPFARBE"] = FARBE;
            dwABAN["ABPBESCHICH"] = FINISH;

            dwABAN["ABAWAKZ"] = "R";
            dwABAN["ABAART"] = dwABPN["ABPART"];
            dwABAN["ABAVAR"] = dwABPN["ABPVAR"];
            dwABAN["ABAFARBE"] = dwABPN["ABPFARBE"];
            dwABAN["ABARESMG"] = dwABPN["ABPSOLLMENGE2"];
            dwABAN["ABAVKENDD"] = dwABPN["ABPSTARTDAT"];
            dwABAN["ABALO"] = PRLO;
            dwABAN["ABALB"] = PRLB;
            dwABAN["ABALP"] = PRLP;
            dwABAN["ABAUSER"] = UserID;
            dwABAN["ABADATE"] = date;
            tbABAUFM.Rows.Add(dwABAN);
            ABAID++;
            #endregion
            return SReturn;
        }
        public DataSet PlanAB55(DataRow dwABA, DataRow dwProc = null)
        {

            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataTable tmpABPOS = INTEXDB.ABPOS.Clone();
            DataTable tmpWDECK = INTEXDB.WDECK.Clone();
            DataTable tmpBAAUF = INTEXDB.BAAUF.Clone();
            DataTable tmpGAAUF = INTEXDB.GAAUF.Clone();
            string filter = "";
            string ENDD = "";
            string STARTD = "";
            decimal GLeng = 0;
            DataRow[] rows = null;
            DataRow dwWASTAMM = null;
            string KRS = "", LFD = "", POS = "";
            string ART = "";
            string VAR = "";
            string WAKZ = "";
            string FARBE = "";
            string BART = "";
            string BVAR = "";
            string BFARBE = "";
            decimal FLeng = 0;
            DataRow dwAPZUORD = null;
            string APZANRKRS = "";
            string APZALFDNR = "";
            DataRow dwABPN = null;
            DataRow dwABAN = null;
            decimal WLeng = 0;
            try
            {
                #region========Validate=================
                ART = dwABA["ABAART"].ToString();
                VAR = dwABA["ABAVAR"].ToString();
                WAKZ = dwABA["ABAWAKZ"].ToString();
                FARBE = dwABA["ABAFARBE"].ToString();
                GLeng = Convert.ToDecimal(dwABA["ABARESMG"].ToString());
                ENDD = dwABA["ABAVKENDD"].ToString();
                if (ENDD == "0")
                {
                    ENDD = date;
                }
                STARTD = GetDateAddDays(ENDD, Convert.ToInt16(0 - LDAB55));
                if (STARTD.Trim() == "") STARTD = "0";
                filter = "WAART='" + ART + "' AND WAVAR='" + VAR + "'";
                rows = SetData.WASTAMM.Select(filter);
                foreach (DataRow row in rows)
                {
                    dwWASTAMM = row;
                }
                if (dwWASTAMM == null)
                {
                    throw new System.Exception("没有对应的工艺档案");
                    return SReturn;
                }
                dwAPZUORD = dwProc;
                if (dwProc == null)
                {
                    filter = "APZSTUFE='R' AND APZART='" + ART
                        + "' AND APZVAR='" + VAR + "' ";
                    rows = SetData.APZUORD.Select(filter);
                    foreach (DataRow row in rows)
                    {
                        dwAPZUORD = row;
                        break;
                    }
                }
                if (dwAPZUORD == null)
                {
                    throw new System.Exception("没有对应的工艺流程");
                    return SReturn;
                }
                APZANRKRS = dwAPZUORD["APZANRKRS"].ToString();
                APZALFDNR = dwAPZUORD["APZALFDNR"].ToString();
                filter = "APFANRKRS='" + APZANRKRS + "' AND APFALFDNR='" + APZALFDNR + "'";
                rows = SetData.APFOLGE.Select(filter);
                foreach (DataRow row in rows)
                {
                    PRLO = row["KSZLO"].ToString();
                    PRLB = row["KSZLB"].ToString();
                    PRLP = row["KSZLP"].ToString();
                }
                decimal WAFBRTL = System.Convert.ToDecimal(dwWASTAMM["WAFBRTL"].ToString());
                decimal WARGRLFD = System.Convert.ToDecimal(dwWASTAMM["WARGRLFD"].ToString());
                decimal WAFGRLFD = System.Convert.ToDecimal(dwWASTAMM["WAFGRLFD"].ToString());
                decimal WARSTDLG = System.Convert.ToDecimal(dwWASTAMM["WARSTDLG"].ToString());
                decimal WARWBRT = System.Convert.ToDecimal(dwWASTAMM["WARWBRT"].ToString());
                if (WARSTDLG == 0)
                {
                    WARSTDLG = 100000;
                }
                #endregion
                #region=======dwABPN==========
                dwABPN = tmpABPOS.NewRow();
                dwABPN["ABPMANDANT"] = "00";
                dwABPN["ABPAUFART"] = "DI";
                dwABPN["ABPAUFKRS"] = "T5";
                dwABPN["ABPAUFLFD"] = ABPLFD;
                dwABPN["ABPAUFPOS"] = ABPOS; ABPOS++;
                dwABPN["ABPNEUBEN"] = UserID;
                dwABPN["ABPNEUDAT"] = date;
                dwABPN["ABPFA"] = 0;
                dwABPN["ABPGA"] = 0;
                dwABPN["ABPQA"] = 0;
                dwABPN["ABPZLO"] = PRLO;
                dwABPN["ABPZLB"] = PRLB;
                //dwABPN["ABPBLO"] = PRLO;
                dwABPN["ABPGESSTA"] = "TE";
                dwABPN["ABPWBSTA"] = "60";
                dwABPN["ABPAESTAT"] = "J";
                dwABPN["ABPSERIE"] = " ";
                dwABPN["ABPKETTAUFT"] = "N";
                dwABPN["ABPMGV"] = 0;
                dwABPN["ABPMGB"] = 0;
                dwABPN["ABPTMCOUNT"] = 3;
                dwABPN["ABPREGEL"] = "00000000";
                dwABPN["ABPLAEAENDA"] = 0;
                dwABPN["ABPWAART"] = dwWASTAMM["WAWAART"];
                dwABPN["ABPWAKZ"] = "R";
                dwABPN["ABPART"] = ART;
                dwABPN["ABPVAR"] = VAR;
                dwABPN["ABPFARBE"] = FARBE;
                dwABPN["ABPANRKR"] = APZANRKRS;
                dwABPN["ABPALFDNR"] = APZALFDNR;
                dwABPN["ABPLIEFDAT"] = ENDD;
                dwABPN["ABPSTARTDAT"] = STARTD;

                dwABPN["ABPSTDLAE"] = 0;
                dwABPN["ABPDIVARTKZ"] = " ";
                dwABPN["ABPSOLLMENGE1"] = GLeng;
                dwABPN["ABPSOLLMENGE2"] = GLeng;
                dwABPN["ABPSOLLMENGE3"] = GLeng * WARWBRT * Convert.ToDecimal(0.001);
                dwABPN["ABPSOLLMENGE4"] = GLeng * WAFBRTL * Convert.ToDecimal(0.001);
                dwABPN["ABPSOLLMENGE5"] = GLeng * WARGRLFD * Convert.ToDecimal(0.001);
                dwABPN["ABPSOLLMENGE6"] = GLeng * WAFGRLFD * Convert.ToDecimal(0.001);
                dwABPN["ABPSOLLMENGE7"] = "0";
                dwABPN["ABPSOLLMENGE8"] = Math.Round(GLeng / (WARSTDLG * Convert.ToDecimal(0.001)), 0);
                decimal ABPANZSTK = Math.Round(GLeng * 10 / WARSTDLG, 0);
                dwABPN["ABPANZSTK"] = ABPANZSTK;
                dwABPN["ABPZUGETGES"] = dwABPN["ABPSOLLMENGE1"];
                dwABPN["ABPSTKLG"] = GLeng / ABPANZSTK;
                dwABPN["ABPSZUSATZKZ1"] = " ";

                dwABPN["ABPSME"] = 1;
                dwABPN["ABPNEUBEN"] = UserID;
                dwABPN["ABPNEUDAT"] = date; ;
                tmpABPOS.Rows.Add(dwABPN);
                #endregion
                #region=======ICC_ABAUFM ================
                var query = from DataRow row in tbABAUFM.AsEnumerable()
                            where row["ABAID"].ToString() == dwABA["ABAID"].ToString()
                            select row;
                foreach (DataRow row in query)
                {
                    decimal ABASANZSTK = Math.Round(Convert.ToDecimal(dwABPN["ABPSOLLMENGE8"].ToString()) * Convert.ToDecimal(0.01), 0);
                    if (ABASANZSTK == 0)
                        ABASANZSTK = 1;
                    decimal ABASSTKLG = Math.Round(Convert.ToDecimal(dwABPN["ABPSOLLMENGE1"].ToString()) / ABASANZSTK, 0) * 10;
                    row["ABAAUFTYP"] = "V";
                    row["ABAAUFKRS"] = dwABPN["ABPAUFKRS"];
                    row["ABAAUFLFD"] = dwABPN["ABPAUFLFD"];
                    row["ABAAUFPOS"] = dwABPN["ABPAUFPOS"];
                    row["ABASANZSTK"] = ABASANZSTK;
                    row["ABASSTKLG"] = ABASSTKLG;
                    row["ABAQTYRESERVE"] = GLeng;
                }
                //产生下层需求
                #region============BAAUF733====================
                DataRow dwWASTKE = null;
                DataRow dwBSGROE = null;
                filter = "WAKART='" + ART + "' AND WAKVAR='" + VAR + "' AND WAKWCOL='" + FARBE + "'";
                rows = SetData.WASTKE.Select(filter);
                foreach (DataRow row in rows)
                {
                    dwWASTKE = row;
                }
                if (dwWASTKE == null)
                {
                    throw new System.Exception("没有对应的织轴工艺档案");
                    return SReturn;
                }
                BART = dwWASTKE["WAKKART"].ToString();
                BVAR = dwWASTKE["WAKKVAR"].ToString();
                BFARBE = dwWASTKE["WAKKFARBE"].ToString();
                filter = "BSGART='" + BART + "'";
                rows = SetData.BSGROE.Select(filter);
                foreach (DataRow row in rows)
                {
                    dwBSGROE = row;
                }
                filter = "BSKART='" + BART + "'";
                rows = SetData.BSSATZ.Select(filter);
                DataRow dwBSSATZ = null;
                foreach (DataRow row in rows)
                {
                    dwBSSATZ = row;
                }

                decimal RT = Convert.ToDecimal(dwWASTKE["WAKEAFAKTR"].ToString());

                if (RT == 0)
                {
                    RT = 10000;
                }
                WLeng = 0;
                WLeng = Convert.ToDecimal(Math.Round(GLeng * RT * Convert.ToDecimal(0.0001) * Convert.ToDecimal(10), 0));
                decimal beamLg = 2500;
                int beamnum = Convert.ToInt16(Math.Ceiling(WLeng / (100 * beamLg)));
                beamLg = Math.Round(WLeng / beamnum);

                dwABAN = tbABAUFM.NewRow();
                dwABAN["ABAID"] = ABAID; ABAID++;
                dwABAN["ABAAUFTYP"] = "N";
                dwABAN["ABAVKAUFTYP"] = "V";
                dwABAN["ABAVKAUFKRS"] = dwABPN["ABPAUFKRS"];
                dwABAN["ABAVKAUFLFD"] = dwABPN["ABPAUFLFD"];
                dwABAN["ABAVKAUFPOS"] = dwABPN["ABPAUFPOS"];
                dwABAN["ABAVKUPOS"] = Right("0000" + dwWASTKE["WAKPOS"].ToString(), 4);
                dwABAN["ABASA"] = 732;
                dwABAN["ABAUMART"] = dwBSGROE["BSGKETTART"];
                dwABAN["ABPWAKZ"] = "R";
                dwABAN["ABPART"] = ART;
                dwABAN["ABPVAR"] = VAR;
                dwABAN["ABPFARBE"] = FARBE;

                dwABAN["ABAWAKZ"] = "W";
                dwABAN["ABAART"] = BART;
                dwABAN["ABAVAR"] = BVAR;
                dwABAN["ABAFARBE"] = BFARBE;

                dwABAN["ABARESMG"] = beamnum * beamLg;
                dwABAN["ABASSTKLG"] = beamLg;
                dwABAN["ABASSTKWG"] = beamLg;
                dwABAN["ABARESKG"] = beamLg;
                dwABAN["ABAREUNIT"] = beamnum;
                dwABAN["BMBAUMKRS"] = "SZ";
                dwABAN["BMBAUMLFD"] = "123456";
                dwABAN["ABABSFDZ"] = dwBSSATZ["BSFDZ"];

                dwABAN["ABAVKENDD"] = dwABPN["ABPSTARTDAT"];
                dwABAN["ABABASMG"] = Convert.ToDecimal(dwWASTKE["WAKEAFAKTR"].ToString()) / 10;
                dwABAN["ABADISPOKZ"] = dwWASTKE["WAKDISPOKZ"];
                dwABAN["ABALLEIST"] = dwWASTKE["WAKLLEIST"];
                dwABAN["ABARLEIST"] = dwWASTKE["WAKRLEIST"];
                dwABAN["ABADOMKZ"] = dwWASTKE["WAKSTBR"];
                dwABAN["ABALO"] = PRLO;
                dwABAN["ABALB"] = PRLB;
                dwABAN["ABALP"] = PRLP;
                dwABAN["ABAUSER"] = UserID;
                dwABAN["ABADATE"] = date;
                tbABAUFM.Rows.Add(dwABAN);
                #endregion
                #region============GAAUF732==========================
                decimal GAKG1 = 0;
                decimal GABASMG2 = 0;

                filter = "WAGART='" + ART + "' AND WAGVAR='" + VAR + "' AND WAGWCOL='" + FARBE + "'";
                rows = SetData.WASTGA.Select(filter);
                foreach (DataRow dwWASTGA in rows)
                {
                    RT = Convert.ToDecimal(dwWASTGA["WAGKGBRUT"]);
                    GAKG1 = Math.Round(GLeng * RT * Convert.ToDecimal(0.001 * 0.01), 0);
                    GABASMG2 = Math.Round(GLeng * RT * Convert.ToDecimal(0.001), 0);
                    dwABAN = tbABAUFM.NewRow();
                    dwABAN["ABAID"] = ABAID; ABAID++;
                    dwABAN["ABAAUFTYP"] = "N";
                    dwABAN["ABAVKAUFTYP"] = "V";
                    dwABAN["ABAVKAUFKRS"] = dwABPN["ABPAUFKRS"];
                    dwABAN["ABAVKAUFLFD"] = dwABPN["ABPAUFLFD"];
                    dwABAN["ABAVKAUFPOS"] = dwABPN["ABPAUFPOS"];
                    dwABAN["ABAVKUPOS"] = dwWASTGA["WAGPOS"];
                    dwABAN["ABASA"] = 732;
                    dwABAN["ABPWAKZ"] = "R";
                    dwABAN["ABPART"] = ART;
                    dwABAN["ABPVAR"] = VAR;
                    dwABAN["ABPFARBE"] = FARBE;

                    dwABAN["ABAWAKZ"] = "G";
                    dwABAN["ABAART"] = dwWASTGA["WAGGART"];
                    dwABAN["ABAVAR"] = dwWASTGA["WAGGVAR"];
                    dwABAN["ABAFARBE"] = dwWASTGA["WAGGFARBE"];
                    dwABAN["ABASSTKLG"] = 0;
                    dwABAN["ABARESMG"] = GAKG1;
                    dwABAN["ABAREUNIT"] = Math.Ceiling(WLeng / 2500);
                    dwABAN["ABAVKENDD"] = dwABPN["ABPSTARTDAT"];
                    dwABAN["ABABASMG"] = dwWASTGA["WAGKGNET"];
                    dwABAN["ABADISPOKZ"] = dwWASTGA["WAGDISPOKZ"];
                    dwABAN["ABALO"] = PRLO;
                    dwABAN["ABALB"] = PRLB;
                    dwABAN["ABALP"] = PRLP;
                    dwABAN["ABAUSER"] = UserID;
                    dwABAN["ABADATE"] = date;
                    tbABAUFM.Rows.Add(dwABAN);
                }
                #endregion
                #endregion
                SReturn.Merge(tmpABPOS);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet PlanAB45(DataRow dwABA, DataRow dwProc = null)
        {

            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataTable tmpABPOS = INTEXDB.ABPOS.Clone();
            DataTable tmpWDECK = INTEXDB.WDECK.Clone();
            DataTable tmpBAAUF = INTEXDB.BAAUF.Clone();
            DataTable tmpGAAUF = INTEXDB.GAAUF.Clone();
            string filter = "";
            string ENDD = "";
            string STARTD = "";
            DataRow[] rows = null;
            DataRow dwBHSATZ = null;
            string ART = "";
            string VAR = "";
            string WAKZ = "";
            string FARBE = "";
            DataRow dwAPZUORD = null;
            string APZANRKRS = "";
            string APZALFDNR = "";
            DataRow dwABPN = null;
            DataRow dwABAN = null;
            decimal WLeng = 0;
            try
            {
                #region========Validate=================
                ART = dwABA["ABAART"].ToString();
                VAR = dwABA["ABAVAR"].ToString();
                WAKZ = dwABA["ABAWAKZ"].ToString();
                FARBE = dwABA["ABAFARBE"].ToString();
                WLeng = Convert.ToDecimal(dwABA["ABARESMG"].ToString());
                decimal BEAMNum = Convert.ToDecimal(dwABA["ABAREUNIT"].ToString());
                ENDD = dwABA["ABAVKENDD"].ToString();
                STARTD = GetDateAddDays(ENDD, Convert.ToInt16(0 - LDAB45));
                if (STARTD.Trim() == "") STARTD = "0";
                filter = "BHKART='" + ART + "' AND BHKVAR='" + VAR + "'";
                rows = SetData.BHSATZ.Select(filter);
                foreach (DataRow row in rows)
                {
                    dwBHSATZ = row;
                }
                if (dwBHSATZ == null)
                {
                    throw new System.Exception("没有对应的工艺档案");
                    return SReturn;
                }
                dwAPZUORD = dwProc;
                if (dwProc == null)
                {
                    filter = "APZSTUFE='B' AND APZART='" + ART + "' AND APZVAR='" + VAR + "' ";
                    filter = "APZSTUFE='B' AND APZART='" + ART + "' ";
                    rows = SetData.APZUORD.Select(filter);
                    foreach (DataRow row in rows)
                    {
                        dwAPZUORD = row;
                    }
                }
                if (dwAPZUORD == null)
                {
                    throw new System.Exception("没有对应的工艺流程");
                    return SReturn;
                }
                APZANRKRS = dwAPZUORD["APZANRKRS"].ToString();
                APZALFDNR = dwAPZUORD["APZALFDNR"].ToString();
                filter = "APFANRKRS='" + APZANRKRS + "' AND APFALFDNR='" + APZALFDNR + "'";
                rows = SetData.APFOLGE.Select(filter);
                foreach (DataRow row in rows)
                {
                    PRLO = row["KSZLO"].ToString();
                    PRLB = row["KSZLB"].ToString();
                    PRLP = row["KSZLP"].ToString();
                }
                decimal BHKGNET = System.Convert.ToDecimal(dwBHSATZ["BHKGNET"]);
                decimal ABPSOLLMENGE5 = Convert.ToDecimal(WLeng) * Convert.ToDecimal(0.001) * BHKGNET * Convert.ToDecimal(0.001);
                var query = from DataRow dwBA in tbABAUFM.AsEnumerable()
                            where dwBA["ABAID"].ToString() == dwABA["ABAID"].ToString()
                            select dwBA;
                foreach (DataRow rx in query)
                {
                    decimal beamLg = Convert.ToDecimal(rx["ABASSTKLG"].ToString());
                    rx["ABASSTKWG"] = Convert.ToDecimal(beamLg) * Convert.ToDecimal(0.001) * BHKGNET * Convert.ToDecimal(0.001);
                    rx["ABARESKG"] = ABPSOLLMENGE5;
                }
                #endregion
                #region=======dwABPN==========
                dwABPN = tmpABPOS.NewRow();
                dwABPN["ABPMANDANT"] = "00";
                dwABPN["ABPAUFART"] = "VW";
                dwABPN["ABPAUFKRS"] = "T4";
                dwABPN["ABPAUFLFD"] = ABPLFD;
                dwABPN["ABPAUFPOS"] = ABPOS; ABPOS++;
                dwABPN["ABPNEUBEN"] = UserID;
                dwABPN["ABPNEUDAT"] = date;
                dwABPN["ABPFA"] = 0;
                dwABPN["ABPGA"] = 0;
                dwABPN["ABPQA"] = 0;
                dwABPN["ABPREGEL"] = "00000000";
                dwABPN["ABPLAEAENDA"] = 0;
                dwABPN["ABPZLO"] = PRLO;
                dwABPN["ABPZLB"] = PRLB;
                dwABPN["ABPBLO"] = PRLO;
                dwABPN["ABPGESSTA"] = "TE";
                dwABPN["ABPWBSTA"] = "60";
                dwABPN["ABPWAART"] = "   ";
                dwABPN["ABPMGV"] = 0;
                dwABPN["ABPMGB"] = 0;
                dwABPN["ABPAESTAT"] = " ";
                dwABPN["ABPTMCOUNT"] = 1;
                dwABPN["ABPSERIE"] = "SZ";
                dwABPN["ABPWAKZ"] = "K";
                dwABPN["ABPART"] = ART;
                dwABPN["ABPVAR"] = VAR;
                dwABPN["ABPFARBE"] = FARBE;
                dwABPN["ABPLIEFDAT"] = ENDD;
                dwABPN["ABPSTARTDAT"] = STARTD;
                dwABPN["ABPANRKR"] = APZANRKRS;
                dwABPN["ABPSTDLAE"] = 0;
                dwABPN["ABPALFDNR"] = APZALFDNR;

                dwABPN["ABPSME"] = "1";
                dwABPN["ABPSOLLMENGE1"] = WLeng;
                dwABPN["ABPSOLLMENGE2"] = WLeng;
                dwABPN["ABPSOLLMENGE3"] = 0;
                dwABPN["ABPSOLLMENGE4"] = 0;
                dwABPN["ABPSOLLMENGE5"] = ABPSOLLMENGE5;
                dwABPN["ABPSOLLMENGE6"] = ABPSOLLMENGE5;
                dwABPN["ABPSOLLMENGE7"] = BEAMNum * 100;
                dwABPN["ABPSOLLMENGE8"] = BEAMNum * 100;
                dwABPN["ABPSZUSATZKZ1"] = " ";
                dwABPN["ABPANZSTK"] = 0;
                dwABPN["ABPZUGETGES"] = 0;
                dwABPN["ABPSTKLG"] = 0;
                dwABPN["ABPKETTAUFT"] = " ";
                tmpABPOS.Rows.Add(dwABPN);
                #endregion
                #region=======ICC_ABAUFM ================
                var qy = from DataRow row in tbABAUFM.AsEnumerable()
                         where row["ABAID"].ToString() == dwABA["ABAID"].ToString()
                         select row;
                foreach (DataRow row in qy)
                {
                    row["ABAAUFTYP"] = "V";
                    row["ABAAUFKRS"] = dwABPN["ABPAUFKRS"];
                    row["ABAAUFLFD"] = dwABPN["ABPAUFLFD"];
                    row["ABAAUFPOS"] = dwABPN["ABPAUFPOS"];
                    row["ABAQTYRESERVE"] = WLeng;
                }
                //产生下层需求          
                #region============GAAUF732==========================
                decimal GAKG1 = 0;
                decimal GABASMG2 = 0;
                decimal RT = 1;
                filter = "BAGART='" + ART + "' AND BAGVAR='" + VAR + "' AND BAGFARBE='" + FARBE + "'";
                rows = SetData.BASTGA.Select(filter);
                foreach (DataRow dwBASTGA in rows)
                {
                    RT = Convert.ToDecimal(dwBASTGA["BAGKGBRUT"]);
                    GAKG1 = Math.Round(WLeng * RT * Convert.ToDecimal(0.001 * 0.01), 0);
                    GABASMG2 = Math.Round(WLeng * RT * Convert.ToDecimal(0.001), 0);
                    dwABAN = tbABAUFM.NewRow();
                    dwABAN["ABAID"] = ABAID; ABAID++;
                    dwABAN["ABAAUFTYP"] = "N";
                    dwABAN["ABAVKAUFTYP"] = "V";
                    dwABAN["ABAVKAUFKRS"] = dwABPN["ABPAUFKRS"];
                    dwABAN["ABAVKAUFLFD"] = dwABPN["ABPAUFLFD"];
                    dwABAN["ABAVKAUFPOS"] = dwABPN["ABPAUFPOS"];
                    dwABAN["ABAVKUPOS"] = dwBASTGA["BAGPOS"];
                    dwABAN["ABPWAKZ"] = "W";
                    dwABAN["ABPART"] = ART;
                    dwABAN["ABPVAR"] = VAR;
                    dwABAN["ABPFARBE"] = FARBE;
                    dwABAN["ABAWAKZ"] = "G";
                    dwABAN["ABAART"] = dwBASTGA["BAGGART"];
                    dwABAN["ABAVAR"] = dwBASTGA["BAGGVAR"];
                    dwABAN["ABAFARBE"] = dwBASTGA["BAGGFARBE"];
                    dwABAN["ABASSTKLG"] = 0;
                    dwABAN["ABARESMG"] = GAKG1;
                    //dwABAN["ABAREUNIT"] = Math.Ceiling(WLeng / 2500);
                    dwABAN["ABAVKENDD"] = dwABPN["ABPSTARTDAT"];
                    dwABAN["ABABASMG"] = dwBASTGA["BAGKGNET"];
                    dwABAN["ABADISPOKZ"] = dwBASTGA["BAGDISPOKZ"];
                    dwABAN["ABAABF"] = dwBASTGA["BAGABF"];
                    dwABAN["ABALO"] = PRLO;
                    dwABAN["ABALB"] = PRLB;
                    dwABAN["ABALP"] = PRLP;
                    dwABAN["ABAUSER"] = UserID;
                    dwABAN["ABADATE"] = date;
                    tbABAUFM.Rows.Add(dwABAN);
                }
                #endregion
                #endregion
                SReturn.Merge(tmpABPOS);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public DataSet PlanAB50(DataRow dwABA, DataRow dwProc = null)
        {

            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataTable tmpABPOS = INTEXDB.ABPOS.Clone();
            DataTable tmpWDECK = INTEXDB.WDECK.Clone();
            DataTable tmpBAAUF = INTEXDB.BAAUF.Clone();
            DataTable tmpGAAUF = INTEXDB.GAAUF.Clone();
            string filter = "";
            string ENDD = "";
            string STARTD = "";
            decimal GLeng = 0;
            DataRow[] rows = null;
            DataRow dwGSDAT = null;
            string KRS = "", LFD = "", POS = "";
            string ART = "";
            string VAR = "";
            string WAKZ = "";
            string FARBE = "";
            string FINISH = "";
            decimal FLeng = 0;
            DataRow dwAPZUORD = null;
            string APZANRKRS = "";
            string APZALFDNR = "";
            DataRow dwABPN = null;
            DataRow dwABAN = null;
            decimal RQTY = 0;
            try
            {
                #region========Validate=================
                ART = dwABA["ABAART"].ToString();
                VAR = dwABA["ABAVAR"].ToString();
                WAKZ = dwABA["ABAWAKZ"].ToString();
                FARBE = dwABA["ABAFARBE"].ToString();
                RQTY = Convert.ToDecimal(dwABA["ABARESMG"].ToString());
                ENDD = dwABA["ABAVKENDD"].ToString();
                STARTD = GetDateAddDays(ENDD, Convert.ToInt16(0 - LDAB50));
                if (STARTD.Trim() == "") STARTD = "0";
                filter = "GSART='" + ART + "' AND GSVAR='" + VAR + "'";
                rows = SetData.GSDAT.Select(filter);
                foreach (DataRow row in rows)
                {
                    dwGSDAT = row;
                }
                if (dwGSDAT == null)
                {
                    throw new System.Exception("没有对应的工艺档案");
                    return SReturn;
                }
                if (dwGSDAT["GSFERTKZ"].ToString() != "E"
                    & dwGSDAT["GSFERTKZ"].ToString() != "F"
                    & dwGSDAT["GSFERTKZ"].ToString() != "X"
                    )
                    return SReturn;

                dwAPZUORD = dwProc;
                if (dwProc == null)
                {
                    filter = "APZSTUFE='G' AND APZART='" + ART + "' AND APZVAR='" + VAR + "' ";
                    rows = SetData.APZUORD.Select(filter);
                    foreach (DataRow row in rows)
                    {
                        dwAPZUORD = row;
                    }
                }
                if (dwAPZUORD == null)
                {
                    throw new System.Exception("没有对应的工艺流程");
                    return SReturn;
                }
                APZANRKRS = dwAPZUORD["APZANRKRS"].ToString();
                APZALFDNR = dwAPZUORD["APZALFDNR"].ToString();
                filter = "APFANRKRS='" + APZANRKRS + "' AND APFALFDNR='" + APZALFDNR + "'";
                rows = SetData.APFOLGE.Select(filter);
                foreach (DataRow row in rows)
                {
                    PRLO = row["KSZLO"].ToString();
                    PRLB = row["KSZLB"].ToString();
                    PRLP = row["KSZLP"].ToString();
                }


                #endregion

                #region=======dwABPN==========
                dwABPN = tmpABPOS.NewRow();
                dwABPN["ABPMANDANT"] = "00";
                dwABPN["ABPAUFART"] = "GP";
                dwABPN["ABPAUFKRS"] = "T2";
                dwABPN["ABPAUFLFD"] = ABPLFD;
                dwABPN["ABPAUFPOS"] = ABPOS; ABPOS++;
                dwABPN["ABPNEUBEN"] = UserID;
                dwABPN["ABPNEUDAT"] = date;
                dwABPN["ABPSERIE"] = " ";
                dwABPN["ABPFA"] = 0;
                dwABPN["ABPGA"] = 0;
                dwABPN["ABPQA"] = 0;
                dwABPN["ABPDIVARTKZ"] = "N";
                dwABPN["ABPTMCOUNT"] = 5;
                dwABPN["ABPREGEL"] = "00000000";
                dwABPN["ABPLAEAENDA"] = 0;
                dwABPN["ABPGESSTA"] = "TE";
                dwABPN["ABPWBSTA"] = "68";
                dwABPN["ABPWAART"] = "   ";
                dwABPN["ABPMGV"] = 0;
                dwABPN["ABPMGB"] = 0;
                dwABPN["ABPZLO"] = PRLO;
                dwABPN["ABPZLB"] = PRLB;

                //dwABPN["ABPBLO"] = PRLO;
                dwABPN["ABPAESTAT"] = " ";
                dwABPN["ABPPOSTYP"] = "CD ";
                dwABPN["ABPWAKZ"] = "G";
                dwABPN["ABPART"] = ART;
                dwABPN["ABPVAR"] = VAR;
                dwABPN["ABPFARBE"] = FARBE;
                dwABPN["ABPLIEFDAT"] = ENDD;
                dwABPN["ABPSTDLAE"] = 0;
                dwABPN["ABPSTARTDAT"] = STARTD;
                dwABPN["ABPANRKR"] = APZANRKRS;
                dwABPN["ABPALFDNR"] = APZALFDNR;

                dwABPN["ABPSME"] = "5";
                
                dwABPN["ABPSOLLMENGE1"] = 0;
                dwABPN["ABPSOLLMENGE2"] = 0;
                dwABPN["ABPSOLLMENGE3"] = 0;
                dwABPN["ABPSOLLMENGE4"] = 0;
                dwABPN["ABPSOLLMENGE5"] = RQTY;
                dwABPN["ABPSOLLMENGE6"] = 0;
                dwABPN["ABPSOLLMENGE7"] = 0;
                dwABPN["ABPSOLLMENGE8"] = 0;
                dwABPN["ABPSZUSATZKZ1"] = " ";
                dwABPN["ABPANZSTK"] = 0;
                dwABPN["ABPZUGETGES"] = 0;
                dwABPN["ABPSTKLG"] = 0;
                dwABPN["ABPKETTAUFT"] = " ";

                tmpABPOS.Rows.Add(dwABPN);
                #endregion

                #region=======ICC_ABAUFM ================
                var query = from DataRow row in tbABAUFM.AsEnumerable()
                            where row["ABAID"].ToString() == dwABA["ABAID"].ToString()
                            select row;
                foreach (DataRow row in query)
                {
                    row["ABAAUFTYP"] = "V";
                    row["ABAAUFKRS"] = dwABPN["ABPAUFKRS"];
                    row["ABAAUFLFD"] = dwABPN["ABPAUFLFD"];
                    row["ABAAUFPOS"] = dwABPN["ABPAUFPOS"];
                    row["ABAQTYRESERVE"] = RQTY;
                }
                //产生下层需求
                #region============GAAUF732====================
                DataRow dwGASTGA = null;
                decimal GAKG1 = 0;
                decimal RT = 0;
                filter = "GAGART='" + ART + "' AND GAGVAR='" + VAR + "' AND GAGFARBE='" + FARBE + "'";
                rows = SetData.GASTGA.Select(filter);
                if (rows.Length == 0)
                {
                    filter = "GAGART='" + ART + "' AND GAGVAR='" + VAR + "'";
                    rows = SetData.GASTGA.Select(filter);
                }
                string addedpos = "";
                foreach (DataRow row in rows)
                {
                    dwGASTGA = row;
                    string YPOS = dwGASTGA["GAGPOS"].ToString();
                    if (addedpos.Contains(YPOS + ";"))
                        continue;
                    addedpos += YPOS + ";";
                    RT = Convert.ToDecimal(dwGASTGA["GAGKGBRUT"]);
                    GAKG1 = Math.Round(RQTY * RT * Convert.ToDecimal(0.00001 * 0.01), 0);
                    dwABAN = tbABAUFM.NewRow();
                    dwABAN["ABAID"] = ABAID; ABAID++;
                    dwABAN["ABAAUFTYP"] = "N";
                    dwABAN["ABAVKAUFTYP"] = "V";
                    dwABAN["ABAVKAUFKRS"] = dwABPN["ABPAUFKRS"];
                    dwABAN["ABAVKAUFLFD"] = dwABPN["ABPAUFLFD"];
                    dwABAN["ABAVKAUFPOS"] = dwABPN["ABPAUFPOS"];
                    dwABAN["ABAVKUPOS"] = dwGASTGA["GAGPOS"];

                    dwABAN["ABPWAKZ"] = "G";
                    dwABAN["ABPART"] = ART;
                    dwABAN["ABPVAR"] = VAR;
                    dwABAN["ABPFARBE"] = FARBE;
                    dwABAN["ABAWAKZ"] = "G";
                    dwABAN["ABAART"] = dwGASTGA["GAGGART"];
                    dwABAN["ABAVAR"] = dwGASTGA["GAGGVAR"];
                    dwABAN["ABAFARBE"] = dwGASTGA["GAGGFARBE"];
                    dwABAN["ABASSTKLG"] = 0;
                    dwABAN["ABARESMG"] = GAKG1;
                    dwABAN["ABAVKENDD"] = dwABPN["ABPSTARTDAT"];
                    dwABAN["ABABASMG"] = dwGASTGA["GAGBASIS"];
                    dwABAN["ABADISPOKZ"] = dwGASTGA["GAGDISPOKZ"];
                    dwABAN["ABALO"] = PRLO;
                    dwABAN["ABALB"] = PRLB;
                    dwABAN["ABALP"] = PRLP;
                    dwABAN["ABAUSER"] = UserID;
                    dwABAN["ABADATE"] = date;
                    tbABAUFM.Rows.Add(dwABAN);
                }
                #endregion
                #endregion
                SReturn.Merge(tmpABPOS);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
        public void Delete(string client, string krs, string lfd, string pos = "000")
        {
            try
            {
                if (INTEXDBC == null)
                {
                    INTEXDBC = new INTEXDBC(OracleDB, proxy);
                }
                DataRow dwData = INTEXDB.ABPOS.NewRow();
                dwData["ABPMANDANT"] = client;
                dwData["ABPAUFKRS"] = krs;
                dwData["ABPAUFLFD"] = lfd;
                DataSet setResult = INTEXDBC.QueryABPOS(dwData, 2);
                if (!setResult.Tables.Contains("ABPOS"))
                    return;
                int count = setResult.Tables["ABPOS"].Rows.Count;
                int cdel = 0;

                foreach (DataRow row in setResult.Tables["ABPOS"].Rows)
                {
                    string posh = row["ABPAUFPOS"].ToString();
                    if (pos != "000")
                    {
                        if (posh != pos)
                            continue;
                    }
                    INTEXDBC.DeleteABPOS(client, krs, lfd, posh);
                    INTEXDBC.DeleteABPR(client, krs, lfd, posh);
                    INTEXDBC.DeleteABAUFM(client, krs, lfd, posh);
                    INTEXDBC.DeleteABFOLGE(client, krs, lfd, posh);
                    INTEXDBC.DeleteWDECK(client, krs, lfd, posh);
                    INTEXDBC.DeleteGAAUF(client, krs, lfd, posh);
                    INTEXDBC.DeleteBAAUF(client, krs, lfd, posh);
                    INTEXDBC.DeleteBABST(client, krs, lfd, posh);
                    INTEXDBC.DeleteABARTE(client, krs, lfd, posh, 1);
                    cdel++;

                }
                if (cdel == count)
                {
                    INTEXDBC.DeleteABKOPF(client, krs, lfd);
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
    }
}